#!/bin/sh
#
# Startup script for Tomcat Servlet Engine
#
# chkconfig: 345 86 14
# description: Tomcat Servlet Engine
# processname: tomcat
# pidfile: /usr/local/jakarta-tomcat/bin/tomcat.pid
#
# User under which tomcat will run
TOMCAT_USER=root
RETVAL=0
CATALINA_HOME=/usr/local/tomcat
JAVA_HOME=/usr/local/java
# start, debug, stop, and status functions
start() {
# Start Tomcat in normal mode
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
if [ $SHUTDOWN_PORT -ne 0 ]; then
echo "Tomcat already started"
else
echo "Starting tomcat..."
su -l $TOMCAT_USER -c '/usr/local/tomcat/bin/startup.sh'
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
while [ $SHUTDOWN_PORT -eq 0 ]; do
sleep 1
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
done
RETVAL=$?
echo "Tomcat started in normal mode"
[ $RETVAL=0 ] && touch /var/lock/subsys/tomcat
fi
}
debug() {
# Start Tomcat in debug mode
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
if [ $SHUTDOWN_PORT -ne 0 ]; then
echo "Tomcat already started"
else
echo "Starting tomcat in debug mode..."
su -l $TOMCAT_USER -c '/usr/local/tomcat/bin/catalina.sh jpda start'
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
while [ $SHUTDOWN_PORT -eq 0 ]; do
sleep 1
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
done
RETVAL=$?
echo "Tomcat started in debug mode"
[ $RETVAL=0 ] && touch /var/lock/subsys/tomcat
fi
}
stop() {
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
if [ $SHUTDOWN_PORT -eq 0 ]; then
echo "Tomcat already stopped"
else
echo "Stopping tomcat..."
su -l $TOMCAT_USER -c '/usr/local/tomcat/bin/shutdown.sh'
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
while [ $SHUTDOWN_PORT -ne 0 ]; do
sleep 1
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
done
RETVAL=$?
echo "Tomcat stopped"
[ $RETVAL=0 ] && rm -f /var/lock/subsys/tomcat /usr/local/jakarta-tomcat/bin/tomcat.pid
fi
}
status() {
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
if [ $SHUTDOWN_PORT -eq 0 ]; then
echo "Tomcat stopped"
else
MODE="normal"
JPDA_PORT=`netstat -vatn|grep LISTEN|grep 8000|wc -l`
if [ $JPDA_PORT -ne 0 ]; then
MODE="debug"
fi
echo "Tomcat running in $MODE mode"
fi
}
case "$1" in
start)
start
;;
debug)
debug
;;
stop)
stop
;;
restart)
stop
start
;;
redebug)
stop
debug
;;
status)
status
;;
*)
echo "Usage: $0 {start|debug|stop|restart|redebug|status}"
exit 1
esac
exit $RETVAL