Manually installing a recent version of Jetty as a service in Linux

While Jetty is available in most of the distributions packages managers, the included versions are rather old (6.1 in Karmic) :

djo@j-pc:~ aptitude show jetty
Package: jetty
State: not installed
Version: 6.1.20-2

So in order to use a recent version of Jetty, you’re on your own.

Here’s a quick post about how to install Jetty as a service on Linux (Ubuntu Karmic in my case), plus how to make it run as a different user account than the root and finally how to enable the automatic deployment of wars placed in Jetty’s webapps directory.

Start by grabbing a more recent version of Jetty from this rather confusing download page. I picked the tar-gz’ed Hightide 7.0.1 version from here.

Extract the archive somewhere on the disk (/home/djo/java/servers/jetty-hightide-7.0.1.v20091125 in my case). And to simplify the upgrade process in the future, I created a symbolic link to this location with a generic name (jetty) :

djo@j-pc:~/java/servers$ ln -s jetty-hightide-7.0.1.v20091125/ jetty

Jetty did most of the work for us by providing the jetty.sh script (under the bin directory). Just copy this file to /init.d/ :

djo@j-pc:~/java/servers$ sudo cp jetty/bin/jetty.sh /etc/init.d/jetty

At this stage, you’re mostly done. You’ll just have to edit /etc/init.d/jetty to specify where jetty is located by adding this line to the very beginning of the file, just after the comments header :

JAVA_HOME=/usr/lib/jvm/java-6-sun
JETTY_HOME=/home/djo/java/servers/jetty

I’ve also indicated my JVM location just to be on the safe side.

By now, you can start jetty by executing :

djo@j-pc:~$ sudo /etc/init.d/jetty start

But wait, before executing the last command, you should know that by running Jetty this way, you’ll end up with a bunch of log files owned by the root user in your home directory. Besides, in my case, the Hudson instance I deployed on Jetty stores it’s configuration, and the generated build artifacts  in the  “/root/.hudson” directory (and are owned by root).  I’d rather have these in my home folder. The same goes for maven (which Hudson uses to perform the build) : the artifacts it fetches are cached in /root/.m2 instead of reusing my local repository.

Jetty can easily be configured to be run by a different user. Simply add this line to the beginning of the /etc/init.d/jetty file :

JETTY_USER=djo

(Don’t forget to replace the user name djo according to your setup)

Now to get jetty to be automatically started on startup and stopped on shutdown, execute the following commands :

djo@j-pc:~$ sudo ln -s /etc/init.d/jetty /etc/rc1.d/K99jetty
djo@j-pc:~$ sudo ln -s /etc/init.d/jetty /etc/rc2.d/S99jetty

And that’s about it.

One last thing : to activate the automatic deployment of war files dropped int jetty’s webapps folder, edit the file ${JETTY_HOME}/etc/jetty.xml to add this snippet :

<Call name="addLifeCycle">
      <Arg>
        <New class="org.eclipse.jetty.deploy.WebAppDeployer">
          <Set name="contexts"><Ref id="Contexts"/></Set>
          <SystemProperty name="jetty.home" default="."/>/webapps
    	  <Set name="parentLoaderPriority">false</Set>
    	  <Set name="extract">true</Set>
    	  <Set name="allowDuplicates">false</Set>
          <SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml
        </New>
      </Arg>
    </Call>
About these ads

7 Responses to Manually installing a recent version of Jetty as a service in Linux

  1. nino says:

    Thanks, was helpfully for me installing jetty7 on karmic

  2. David says:

    Great post, only place I could find this information. Thanks

  3. Div says:

    I followed the same on my Ubuntu 9.04 by downloading jetty-6.1.24, but when I try to start jetty using sudo /etc/init.d/jetty start , its gets me the following error

    ** ERROR: Oops! Jetty doesn’t appear to be installed in /home/div/software_sources/jetty
    ** ERROR: /home/div/software_sources/jetty/etc/jetty.xml is not readable!

    Any idea about this?

    • jawher says:

      Hi,
      Can you post here the output of the command:

      ls -l /home/div/software_sources/jetty
      
      • Div says:

        Here goes,

        total 244
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:11 bin
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:11 contexts
        drwxr-xr-x 15 sodel sodel 4096 2010-04-24 03:12 contrib
        drwxr-xr-x 3 sodel sodel 4096 2010-04-24 03:11 distribution
        drwxr-xr-x 9 sodel sodel 4096 2010-04-24 03:12 examples
        drwxr-xr-x 12 sodel sodel 4096 2010-04-24 03:12 extras
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:11 javadoc
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:12 LICENSES
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:11 logs
        drwxr-xr-x 15 sodel sodel 4096 2010-04-24 03:12 modules
        -rw-r–r– 1 sodel sodel 1621 2009-11-03 05:27 NOTICE.txt
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:11 patches
        -rw-r–r– 1 sodel sodel 9899 2010-04-22 00:11 pom.xml
        -rw-r–r– 1 sodel sodel 4253 2007-10-04 10:00 README.txt
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:12 resources
        -rw-r–r– 1 sodel sodel 166148 2010-04-21 22:32 VERSION.txt
        drwxr-xr-x 2 sodel sodel 4096 2010-04-24 03:11 webapps

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: