3

I installed tomcat servlet but I need to autostart it on boot. How to do that?

1

2 Answers 2

2

You need to create an init script for tomcat and add it to the correct runlevel init script.

Advice adapted from here http://www.raibledesigns.com/tomcat/boot-howto.html

Create an init script /etc/init.d/tomcat/ for tomcat, changing the value for catalina home to the correct location:

#!/bin/bash
#
# tomcat        
#
# chkconfig: 
# description:  Start up the Tomcat servlet engine.

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


RETVAL=$?
CATALINA_HOME="/usr/apps/apache/tomcat/jakarta-tomcat-4.0.4"

case "$1" in
 start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
        echo $"Starting Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/startup.sh
        fi
    ;;
 stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
        echo $"Stopping Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
        fi
    ;;
 *)
    echo $"Usage: $0 {start|stop}"
    exit 1
    ;;
esac

exit $RETVAL

Then add a link to the rc5.d folder - /etc/rc5.d/

sudo ln -s /etc/init.d/tomcat /etc/rc5.d/S71tomcat
0
0

One way to start the tomcat on the startup is to run it using cron using the @reboot attribute:

open up a terminal and type :

sudo crontab -e

at the end of the file enter the command:

@reboot /`PATH_TO_WHERE_TOMCAT_INSTALLED`/bin/startup.sh

save the file and exit.

The above command will run the command once everytime computer boots up.

You must log in to answer this question.