Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty bash script works only with root user

Tags:

linux

jetty

I have installed Jetty 9 (latest version) by extracting the archive in /opt/jetty.

The start.jar runs fine, but I want the bash service bin/jetty.sh, to be run by a non-root user.

The issue I'm having with the bash script is that : when I dont specify a value for $JETTY_USER in /etc/default/jetty (it uses root user), Jettyworks. But when I assign a value to it, Jetty fail with the message: Starting Jetty: FAILED, and no log.

So, how do I create a user that can run the jetty?

like image 398
Hakim Avatar asked Aug 01 '13 16:08

Hakim


2 Answers

I know that this question is old, but since this behaviour bugged me recently as well, here it's my hint. In my case it was Jetty 8.x on Centos 6.5, and I had the exact similar behaviour: jetty starting flawlessly when launched on command line both as root and as the newly created jetty user, but failing to start whenever trying to run it as a service and specifying a user through the variable JETTY_USER in /etc/default/jetty. Logs were completely empty.

The trick in my case was that no directory was openly specified for logs in the JETTY_LOGS variable. When run directly as a user, when Jetty can't access a normal directory for logs it will try to create one for the user. With the startup script in Centos/RH systems, though, the process is ran by a 'su - -c "command" user' which seems to break that kind of behaviour. No complain is filed in the logs file, as the process breaks right when trying to access them, and both stdout and stderr are redirected to the logs.

To debug you exact permissions problem, try running the server through a "su -c" like the script does; the difference is that you will finally have your stderr on the console. And for the future, also manually create a jetty logs directory with the right permissions, and specify it inside the JETTY_LOGS variable: much less of an headache!

like image 96
stoned Avatar answered Sep 20 '22 05:09

stoned


I faced the same issue. In my case I installed Jetty v 9.2.10.v201503 on pcDuino v3, Ubuntu 14.04 following step-by-step installation guidelines “Startup a Unix Service using jetty.sh” (see documentation on eclipse.org).

Since the steps are run as root, I ended up with mixed ownership (root and jetty) of files and directories in $JETTY_BASE directory.

I added JETTY_LOGS=$JETTY_BASE/logs and JETTY_USER=jetty to the /etc/default/jetty file and reissued chown –R jetty:jetty $JETTY_BASE.

After these steps Jetty runs under credentials of jetty user. Though it was pretty easy, I hope that this note might be useful for others who are not professional admins.

like image 41
jmasa Avatar answered Sep 18 '22 05:09

jmasa