Wednesday, May 7, 2014

Automated tomcat start up on server reboot



Automated start up on server reboot


Create a new tomcat user using the following command:
adduser tomcat

Create the following file /etc/init.d/tomcat:
#!/bin/bash
#
# tomcat       
#
# chkconfig:
# description: Start up the Tomcat servlet engine.

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


RETVAL=$?
CATALINA_HOME="/usr/local/apache-tomcat-7.0.52"

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

Edit the file and change CATALINE_HOME to the location of where tomcat is found.

Grant execution write of the new file using the following command:
chmod 755 /etc/init.d/tomcat

Reassign the owner of the tomcat folder and all subfolders to the tomcat user:
chown tomcat:tomcat –R /usr/local/apache-tomcat-7.0.52


To start up on server reboot:
ln –s ../init.d/tomcat S71tomcat
 

No comments:

Post a Comment