Tomcat linux service
From WeWeWeb Wiki
#!/bin/sh
#
# Startup script for Tomcat, the Apache Servlet Engine
#
# chkconfig: 345 80 20
# description: Tomcat is the Apache Servlet Engine RI for Servlet 2.3/JSP 1.2
# processname: tomcat
# pidfile: /var/run/tomcat.pid
# config: /etc/tomcat4/conf/tomcat4.conf
#
# Source function library.
if [ -x /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi
# Set JAVA_HOME
# JAVA_HOME=/opt/java
# JRE_HOME=/opt/java
# Set in CATALINA.sh
# Get Tomcat config
TOMCAT_CFG="/etc/tomcat4/conf/tomcat4.conf"
[ -r "$TOMCAT_CFG" ] && . "${TOMCAT_CFG}"
# Path to the tomcat launch script (direct don't use wrapper)
TOMCAT_START_SCRIPT=/opt/tomcat/bin/startup.sh
TOMCAT_STOP_SCRIPT=/opt/tomcat/bin/shutdown.sh
# Tomcat name :)
TOMCAT_PROG=tomcat
# if TOMCAT_USER is not set, use tomcat like Apache HTTP server
if [ -z "$TOMCAT_USER" ]; then
TOMCAT_USER="tomcat"
fi
# Since the daemon function will sandbox $tomcat
# no environment stuff should be defined here anymore.
# Please use the /etc/tomcat.conf file instead ; it will
# be read by the $tomcat script
RETVAL=0
# See how we were called.
start() {
echo -n "Starting $TOMCAT_PROG: "
#chown -R $TOMCAT_USER:$TOMCAT_USER $CATALINA_HOME/logs
#chown -R $TOMCAT_USER:$TOMCAT_USER $CATALINA_HOME/work
#chown -R $TOMCAT_USER:$TOMCAT_USER $CATALINA_TMPDIR
#chown -R $TOMCAT_USER:$TOMCAT_USER $CATALINA_HOME/webapps
if [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $TOMCAT_USER $TOMCAT_START_SCRIPT
else
su - $TOMCAT_USER -c "$TOMCAT_START_SCRIPT"
fi
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
return $RETVAL
}
stop() {
echo -n "Stopping $TOMCAT_PROG: "
if [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $TOMCAT_USER $TOMCAT_STOP_SCRIPT
else
su - $TOMCAT_USER -c "$TOMCAT_STOP_SCRIPT"
fi
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat /var/run/tomcat.pid
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
# Ugly hack
# We should really make sure tomcat
# is stopped before leaving stop
sleep 2
start
;;
condrestart)
if [ -f /var/run/tomcat.pid ] ; then
stop
start
fi
;;
*)
echo "Usage: $TOMCAT_PROG {start|stop|restart|condrestart}"
exit 1
esac
exit $RETVAL