Last active
February 3, 2016 13:37
-
-
Save alistairhenderson/89f13d5fec247f034048 to your computer and use it in GitHub Desktop.
Startup script for Tomcat 6.0 for project.net installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Startup script for Tomcat 6.0, the Apache Servlet Engine | |
# | |
# chkconfig: - 80 20 | |
# description: Tomcat 6 | |
# processname: tomcat | |
# pidfile: /var/run/tomcat6.pid | |
# config: | |
# | |
# Source function library. | |
if [ -x /etc/rc.d/init.d/functions ]; then | |
. /etc/rc.d/init.d/functions | |
fi | |
# Get Tomcat config | |
# PID_FILE - must match CATALINA_PID in catalina.sh | |
PID_FILE=/opt/apache-tomcat/bin/startstop.pid | |
# Path to the tomcat launch script (direct don't use wrapper) | |
TOMCAT_SCRIPT=/opt/apache-tomcat/bin/catalina.sh | |
# Tomcat name | |
TOMCAT_PROG=tomcat | |
# SYSTEM lock file | |
SYSTEM_LOCK_FILE=/opt/apache-tomcat/bin/startstop.lock | |
# How long to wait for shutdowns | |
SHUTDOWN_WAIT=15 | |
# if TOMCAT_USER is not set | |
if [ -z "$TOMCAT_USER" ]; then | |
TOMCAT_USER="pnet" | |
fi | |
# Since the daemon function will sandbox $tomcat | |
# no environment stuff should be defined here anymore. | |
RETVAL=0 | |
# See how we were called. | |
start() { | |
echo -n "Starting $TOMCAT_PROG: " | |
if [ -f $SYSTEM_LOCK_FILE ]; then | |
if [ -f $PID_FILE ]; then | |
read kpid < $PID_FILE | |
if checkpid $kpid 2>&1; then | |
echo "process allready running" | |
return -1 | |
else | |
echo "lock file found but no process running for pid $kpid, continuing" | |
/bin/rm -f $SYSTEM_LOCK_FILE $PID_FILE | |
fi | |
fi | |
fi | |
export CATALINA_PID=$PID_FILE | |
if [ -x /etc/rc.d/init.d/functions ]; then | |
daemon --user $TOMCAT_USER $TOMCAT_SCRIPT start | |
else | |
su - $TOMCAT_USER -c "$TOMCAT_SCRIPT start" | |
fi | |
RETVAL=$? | |
echo | |
[ $RETVAL = 0 ] && touch $SYSTEM_LOCK_FILE | |
return $RETVAL | |
} | |
stop() { | |
echo -n "Stopping $TOMCAT_PROG: " | |
if [ -f $SYSTEM_LOCK_FILE ]; 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=$? | |
if [ $RETVAL = 0 ]; then | |
count=0; | |
if [ -f $PID_FILE ]; then | |
read kpid < $PID_FILE | |
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 $SYSTEM_LOCK_FILE $PID_FILE | |
fi | |
fi | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
sleep 2 | |
start | |
;; | |
condrestart) | |
if [ -f $PID_FILE ] ; then | |
stop | |
start | |
fi | |
;; | |
*) | |
echo "Usage: $TOMCAT_PROG {start|stop|restart|condrestart}" | |
exit 1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment