Debian Configuration– Tomcat on Boot

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:

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

# /etc/init.d/tomcat6: start Tomcat6 server.

test -f /opt/apache-tomcat-6.0.30/bin/ || 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/ | 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/ | logger -t Tomcat6

*) echo "Usage: /etc/init.d/tomcat6 {start|stop}"
exit 2
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 /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 thoughts on “Debian Configuration– Tomcat on Boot

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.