Install Jetty as a service on CentOS

It seems hard to find a complete step-by-step tutorial to install Jetty as a service (especially on CentOS), some of the tutorial online is somewhat outdated or does not work, so I will share what I’ve learnt. (painfully) Perhaps this tutorial will also be outdated at some point in the future, so I will state the current version of the software I use clearly.

This tutorial will cover achieving the following on CentOS 6+:

  1. Able to run jetty server as “jetty” user
  2. Able to start jetty by “sudo service start jetty”
  3. Able to start jetty when the system boot
  4. Able to specify a base directory for jetty to run instead of using JETTY_HOME

Getting started

1. make sure latest java is installed:

2. Download Jetty 9.3, go to this download page and download the Stable-9 version, I prefer the .tar.gz

Uncompress and move it to desired installation path, some tutorial may suggest you install to /opt/, but I prefer /usr/local,

Optional Symbolic link creation, so you can get a nice and clean “/usr/local/jetty/” path which points to the actual path

Jetty user and base dir

3. create jetty user, assign home directory as /home/jetty (actually home dir is not very important):

This is important: don’t use the shell /bin/false
(if you did, edit /etc/passwd to change it back)

4. We will use /home/jetty/ as the JETTY_BASE. To init the base dir with initial configs (required) :

add any modules you want in the “add-to-start” argument, you can still edit the start.ini in your base dir anytime

Edit Jetty Config

5. We will edit the /etc/defaults/jetty, this is where we config the main paths that Jetty use, this is my recommended config, if you follow my procedure, you can just use this without any changes

6. Create the directories manually

Also make sure jetty home is accessible by jetty user

Install Jetty as Service

7. add to /etc/init.d, create a symbolic link to the /etc/init.d directory by:

8. Verify the config:

9. Start jetty:

10. Launch jetty at startup

Hope this tutorial helps!


Still getting FAILED or cannot start jetty? you may have to dig into the script, try to run the actual command that it use.

Usually it’s one of the following problem:

  1. Permission of the log path / pid file path not writable by “jetty” user
  2. jetty user is not created or something wrong, try to run
    su - jetty -c "whoami" , it should output jetty. If it just login to root shell, you may have set the shell of “jetty” to /bin/false

One thought on “Install Jetty as a service on CentOS

  1. By the way, path to temp in default/jetty should be TMPDIR=/home/jetty/tmp.. or mkdir -p /home/jetty/temp, either way ;).. Just got some weird errors when it was not pointing to the existing folder.

Share your thoughts