Smathermather's Weblog

Remote Sensing, GIS, Ecology, and Oddball Techniques

Debian Configuration– Tomcat on Boot

Posted by smathermather on January 24, 2011

Start-up scripts in Debian Linux aren’t exactly straight forward for the un-initiated.  Actually, if memory serves me, they aren’t any more straight forward on Ubuntu Linux either, but such is heredity.

We are transitioning some of our GeoServer instances over to 64-bit Debian Linux.  In my test Ubuntu environment, I had a hack in place to force the Tomcat Java Servlet to launch on startup, but it was a hack and not very deep in understanding.  Here, I will go somewhat deeper.

So, why not just use a package manager to install Tomcat, thus bi-passing the need for setting up my own service?  GeoWebCache’s configuration guide discouraged me:

Due to licensing issues, many Linux distributions come with a variety of Java environments. Additionally, to minimize the chance of a security breach with default settings, most versions of Tomcat are configured to not allow access to the file system. Therefore, it is highly recommended to follow these instructions, even if you already have a servlet container set up.

Well, ok then.  I’ll roll my own.

Following the installation instructions for GeoWebCache is straightforward, but I have no interest in starting Tomcat manually, except when necessary.

Enter, the google:

I modified code from this source:

http://linux.derkeiler.com/Mailing-Lists/Debian/2008-12/msg00099.html

to get something that looks like this as my script to run a Tomcat6 startup shell:


#!/bin/sh
# /etc/init.d/tomcat6: start Tomcat6 server.


test -f /opt/apache-tomcat-6.0.30/bin/startup.sh || exit 0

case "$1" in

start) export JAVA_HOME=/opt/jre1.6.0_23/bin/
logger -t Tomcat6 "Starting Tomcat 6..."
exec /opt/apache-tomcat-6.0.30/bin/startup.sh | logger -t Tomcat6
;;

stop) export JAVA_HOME=/opt/jre1.6.0_23/bin/
logger -t Tomcat6 "Shutting down Tomcat 6..."
exec /opt/apache-tomcat-6.0.30/bin/shutdown.sh | logger -t Tomcat6
;;

*) echo "Usage: /etc/init.d/tomcat6 {start|stop}"
exit 2
;;
esac
exit 0

I still need to deploy this as a service. The first step is to sudo or su root and place this in my /etc/init.d directory.

sudo cp tomcat6.sh /etc/init.d/.

Now this needs loaded as a service.  Normal multi-user run levels for debian are 2-5.  0, 1 and 6 are “System Halt”, “Single User Mode”, and Reboot, so we set the start flag to run on multi-user logins, and to stop in the other run levels, like reboot.

update-rc.d apache2 start 99 2 3 4 5 . stop 99 0 1 6 .

Ah, now it works a charm.  FYI, I did my testing of the script while logged in as root, so I wouldn’t have to restart with every change.  I figured being logged in as root would simulate, pretty closely, the boot environment, relative to being an ordinary user.

3 Responses to “Debian Configuration– Tomcat on Boot”

  1. FYI,
    “update-rc.d apache2 start 99 2 3 4 5 . stop 99 0 1 6 .” needs run with sudo or as root.

  2. I have a typo above:

    “update-rc.d apache2 start 99 2 3 4 5 . stop 99 0 1 6 .”
    should be:
    “update-rc.d tomcat6 start 99 2 3 4 5 . stop 99 0 1 6 .”

  3. […] revised my startup script for Tomcat to use a non-privileged user for security reasons. I used the following page as my […]

Leave a Reply

Fill in your details below or click an icon to log in:

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

 
%d bloggers like this: