#!/bin/sh # # Startup script for Tomcat, the Apache Servlet Engine # # chkconfig: - 80 20 # description: Tomcat is the Apache Servlet Engine # processname: tomcat # pidfile: /var/run/tomcat.pid # config: @@@TCSCONF@@@/@@@PROCNAME@@@.conf # # Gomez Henri <hgomez@slib.fr> # Keith Irwin <keith_irwin@non.hp.com> # Nicolas Mailhot <nicolas.mailhot@one2team.com> # # version 1.02 - Removed initlog support # version 1.03 - Removed config: # version 1.04 - tomcat will start before httpd and stop after httpd # version 1.05 - jdk hardcoded to link /usr/java/jdk and tomcat runs as "nobody" # version 1.06 - split up into script and config file # version 1.07 - Rework from Nicolas ideas # version 1.08 - Add -nout at start mode to make stdout/stderr goes to file # version 1.09 - Fix work dir permission at start time, switch to use tomcat # version 1.10 - rename tomcat to tomcat3 # version 1.11 - Fallback to su direct use on systems without Redhat/Mandrake init.d functions # version 1.12 - remove initial start/stop level for chkconfig (- 80 20) # version 1.13 - Add support for TOMCAT_PID env var # # Source function library. if [ -x /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions fi # Get Tomcat config TOMCAT_CFG="@@@TCSCONF@@@/@@@PROCNAME@@@.conf" [ -r "$TOMCAT_CFG" ] && . "${TOMCAT_CFG}" # Path to the tomcat launch script (direct don't use wrapper) TOMCAT_SCRIPT=/usr/bin/d@@@PROCNAME@@@ # Tomcat name :) TOMCAT_PROG=@@@PROCNAME@@@ # if TOMCAT_USER is not set, use nobody like Apache HTTP server if [ -z "$TOMCAT_USER" ]; then TOMCAT_USER="@@@PROCNAME@@@" fi # Since the daemon function will sandbox tomcat # no environment stuff should be defined here anymore. # Please use the @@@TCSCONF@@@/@@@PROCNAME@@@.conf file instead ; it will # be read by the tomcat script RETVAL=0 # See how we were called. start() { echo -n "Starting $TOMCAT_PROG: " if [ -f /var/lock/subsys/@@@PROCNAME@@@ ] ; then echo "process allready running" return -1 else chown -R $TOMCAT_USER:$TOMCAT_USER /var/log/@@@PROCNAME@@@ chown -R $TOMCAT_USER:$TOMCAT_USER /var/spool/@@@PROCNAME@@@ chown -R $TOMCAT_USER:$TOMCAT_USER @@@TCINST@@@/webapps chown -R $TOMCAT_USER:$TOMCAT_USER @@@TCINST@@@/modules chown -R $TOMCAT_USER:$TOMCAT_USER @@@TCINST@@@/internal export TOMCAT_PID=/var/run/@@@PROCNAME@@@.pid touch $TOMCAT_PID chown -R $TOMCAT_USER:$TOMCAT_USER $TOMCAT_PID if [ -x /etc/rc.d/init.d/functions ]; then daemon --user $TOMCAT_USER $TOMCAT_SCRIPT start -noout else su - $TOMCAT_USER -c "$TOMCAT_SCRIPT start -noout" fi RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/@@@PROCNAME@@@ return $RETVAL fi } stop() { echo -n "Stopping $TOMCAT_PROG: " if [ -f /var/lock/subsys/@@@PROCNAME@@@ ] ; then if [ -x /etc/rc.d/init.d/functions ]; then daemon --user $TOMCAT_USER $TOMCAT_SCRIPT stop else su - $TOMCAT_USER -c "$TOMCAT_SCRIPT stop" fi RETVAL=$? echo if [ $RETVAL = 0 ]; then count=0; if [ -f /var/run/@@@PROCNAME@@@.pid ]; then read kpid < /var/run/@@@PROCNAME@@@.pid let kwait=$SHUTDOWN_WAIT until [ `ps --pid $kpid | grep -c $kpid` = '0' ] || [ $count -gt $kwait ] do echo "waiting for processes to exit"; sleep 1 let count=$count+1; done if [ $count -gt $kwait ]; then echo "killing processes which didn't stop after $SHUTDOWN_WAIT seconds" kill -9 $kpid fi fi rm -f /var/lock/subsys/@@@PROCNAME@@@ /var/run/@@@PROCNAME@@@.pid fi fi } # 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 # we could check here if the ajp12.id still exist sleep 2 start ;; condrestart) if [ -f /var/run/@@@PROCNAME@@@.pid ] ; then stop start fi ;; *) echo "Usage: $TOMCAT_PROG {start|stop|restart|condrestart}" exit 1 esac exit $RETVAL