Thursday, June 18, 2015

How to run tomcat as service

Make sure there is a valid user "tomcat" and that this user has rw permissions in the $CATALINA_HOME/conf and $CATALINA_HOME/logs directories. Also make sure that $JAVA_HOME is set. You will start Tomcat as user "tomcat" to avoid running it as root.

Save the following scripts as /etc/init.d/tomcat.They will automatically be read and run at boot time. Check the log files if it does not start properly.


Do like below for rc3.d rc5.d rc4.d
Make a link to it from /etc/rc5.d such as:
cd /etc/rc5.d
sudo ln -s ../init.d/tomcat S71tomcat


Script for init.d

#!/bin/bash
#
# tomcat        where is tomcat mention is script that need to replace with user
#
# chkconfig: 345 20 80
# description:     Start up the Tomcat servlet engine.

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


RETVAL=$?
CATALINA_HOME="/tomcat-apache path/apache-tomcat-7.0.62"

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

For boot time active : chkconfig --level 345 tomcat on

To Find from which user service running
ps aux | egrep 'process name' typically will show from which user is service running as.

0 comments:

Post a Comment