gitbucket icon indicating copy to clipboard operation
gitbucket copied to clipboard

Cannot run gitbucket under a non root user in Linux

Open gitgit3 opened this issue 1 year ago • 1 comments
trafficstars

Issue

downloaded gitbucket from here: wget https://github.com/gitbucket/gitbucket/releases/download/4.41.0/gitbucket.war

java -version openjdk version "11.0.24" 2024-07-16 OpenJDK Runtime Environment (build 11.0.24+8-post-Ubuntu-1ubuntu320.04) OpenJDK 64-Bit Server VM (build 11.0.24+8-post-Ubuntu-1ubuntu320.04, mixed mode, sharing)

I downloaded an ran gitbucket on my remote server with no problems as root, using standalone, i.e: java -jar /opt/gitbucket/gitbucket.war

I was able to login over http and upload sources code, create users etc.. everything worked as expected.

So I then followed this page to create a gitbucket user and run as a service: https://github.com/gitbucket/gitbucket/wiki/Install-as-a-systemd-Service

but there were problems starting the service so I tried running as standalone under the new user to check file permissions and such like: sudo -u gitbucket java -jar /opt/gitbucket/gitbucket.war --port=8080 --gitbucket.home=/opt/gitbucket/gitbucket-data

and the process hangs after the debug line: 17:15:42.363 [main] INFO g.core.servlet.InitializeListener - Initialize plugins

the port is open at this point, including from a remote location: nmap -p8080 localhost PORT STATE SERVICE 8080/tcp open http-proxy

Browsing from a remote location gives: HTTP ERROR 503 Service Unavailable

I can find no logs or output to give me any clues.

gitgit3 avatar Aug 13 '24 17:08 gitgit3

Well, I found the problem.

After the line logger.info("Initialize plugins") which is line 90 in core/servlet/InitializeListener.scala, the call to PluginRegistry.initialize() hangs. So we move to core/plugin/PluginRegistry.scala on line 273, there is a deleteDirectory(). It looks like this is deleting any previously unpacked plugins so that it can recreate the plugins fresh.

The problem is that if you had previously run the command as root and then try and run as a non root user, as I did, you will find that the new user does not have the permissions to delete the old files. And the process hangs there.

I would suggest that the fix here should be for FileUtils.deleteDirectory(installedDir) to throw an exception,, log it and terminate, which would of course have saved me some hours today.

I am not providing a fix, on account of never having even heard of 'scala'.

gitgit3 avatar Aug 15 '24 14:08 gitgit3

FileUtils.deleteDirectory(installedDir) actually throws an exception but it wasn't logged.

https://github.com/gitbucket/gitbucket/pull/3804 would improve the situation.

takezoe avatar Sep 22 '25 22:09 takezoe