|
|
|||||||||||||||
|
Introduction
|
|
There are two stages to making a Tomcat installation start automatically on Debian. The first is to write an "init script" for the process. The second is to install that script into the appropriate places to make the system execute it at start-up and shutdown. |
|
Finally, for bonus marks, we make the log files rotate weekly. |
|
These instructions assume that you are using a /usr/local installation of Tomcat similar to that described in the instructions on the Luminas site. |
|
The init-script
|
|
This init script is a copy of /etc/init.d/skeleton, but Tomcat already provides a script to start itself up and shut itself down, so we'll use that instead of start-stop-daemon. |
#! /bin/sh
#
# tomcat Start up tomcat
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Tomcat and Cocoon by <markj@luminas.co.uk>
export JAVA_HOME=/usr/lib/j2sdk1.3
export TOMCAT_HOME=/usr/local/jakarta-tomcat-3.2.3
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=$TOMCAT_HOME/bin/tomcat.sh
NAME=tomcat
DESC="tomcat"
test -f $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
/usr/bin/X11/Xvfb :0 &
echo $! >/var/run/tomcat-xvfb.pid
$DAEMON start >>/var/log/tomcat 2>&1
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
$DAEMON stop >>/var/log/tomcat 2>&1
kill $(cat /var/run/tomcat-xvfb.pid)
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
$DAEMON stop >>/var/log/tomcat 2>&1
sleep 1
$DAEMON start >>/var/log/tomcat 2>&1
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
|
Adding symlinks to rc?.d
|
|
Next, we need to add symlinks to the appropriate rc?.d directories to make the system start Tomcat up at boot and shut it down at halt/reboot. |
|
Debian comes with the handy tool "update-rc.d" for this purpose, so we shall use it with the simple commands: |
update-rc.d tomcat start 91 2 3 4 5 . stop 20 0 1 6 .
|
We have chosen 91 and 20 because these are the same as the sequence numbers that Apache uses. |
|
Rotate the logs
|
|
Finally, we use the logrotate package to keep the logs under control. In some configurations, Tomcat can generate quite a large amount of logs, even on a modestly active server, so rotation is essential. |
|
By rotation, we mean that the current log file is moved to a different name and a new log file started. The previous log files are all moved back one in the "queue" and the last one is deleted. We achieve this with the following piece of configuration added to the end of /etc/logrotate.conf: |
/var/log/tomcat {
weekly
rotate 4
postrotate
/etc/init.d/tomcat restart
endscript
compress
}
|
Feedback
|
|
If you notice any errors or omissions or have any comments about this quickstart guide, please get in touch. Email info@luminas.co.uk or see the Contacts page for other ways of getting in touch. |
![]() |