Paul Jones - 2006-07-10

Once you get things running you may want to add Tomcat as a Linux Service.  This can be done as follows:

1 - Stop any Tomcat servers that are running.

2 - Create a Start/Stop Script like the following. Simply cut and paste the following into your favorite text editor (between and not including the lines of asterisks) .

**************************************************

#    This is the init script for starting up the
#        Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

tomcat=/usr/local/jakarta-tomcat
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
export JAVA_HOME=/usr/local/jdk

start(){
    echo -n $"Starting Tomcat service: "
    #daemon -c
    $startup
    RETVAL=$?
    echo
}

stop(){
    action $"Stopping Tomcat service: " $shutdown   
    RETVAL=$?
    echo
}

restart(){
    stop
    start
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        # This doesn't work ;)
    status tomcat
    ;;
  restart)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart}"
    exit 1
esac

exit 0

**************************************************

3 - Edit the lines that start with ‘tomcat’ and ‘export’ to match where you installed Tomcat and your jdk.

4 - Save to /etc/init.d and chmod

Save the edited file above to /etc/init.d directory as "tomcat" (at least on most newer releases since /etc/init.d is a standard now). Then you have to allow execute access to the script, so run:

chmod a+x tomcat

5 -  Add to appropriate run level directories
The easy way to do this is to just simply run:

chkconfig --add tomcat

6 - Start the Tomcat service, and you should be off to the races!

Good luck,

Paul.