Skip to content

Setting up Jetty 7.4.x on CentOS 5.x as non-root daemon

Updated: at 06:30 AM

First, please make sure you’ve already installed JDK on your Centos box. There are tons of tutorials on how to do that :). Now we will download and install Jetty, at the time of this writing, the latest version of Jetty is 7.4.5.v20110725. Every command listing below must be run as user root.

cd /opt
wget http://download.eclipse.org/jetty/stable-7/dist/jetty-distribution-7.4.5.v20110725.tar.gz
tar xzvf jetty-distribution-7.4.5.v20110725.tar.gz
ln -s jetty-distribution-7.4.5.v20110725 jetty

OK, we’ve just installed Jetty to /opt/jetty. Now we will setup Jetty to run on startup

cd /etc/init.d
ln -s /opt/jetty/bin/jetty.sh jetty
chkconfig --add jetty
chkconfig --level 345 jetty on

It’s a good practice to run Jetty as a non-root user, let’s create a normal user called jetty

useradd -m jetty
chown -R jetty:jetty /opt/jetty

Now edit the startup script of Jetty located at /opt/jetty/bin/jetty.sh to include the following lines at the beginning (right after a bulk of commented lines describing various variables for Jetty)

JAVA_HOME=/opt/java
JAVA=$JAVA_HOME/bin/java
JAVA_OPTIONS=" -server -Xms256m -Xmx1024m -XX:+DisableExplicitGC "
JETTY_HOME=/opt/jetty
JETTY_USER=jetty
JETTY_PORT=7070
JETTY_HOST=0.0.0.0 # If you don't set this to 0.0.0.0, jetty only listen on localhost
JETTY_LOGS=/opt/jetty/logs/

Now start up it:

service jetty start

Open your browser and navigate to http://:7070/

Hope this help!