#!/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
TOMCAT_HOME=/dev/vol1/apache-tomcat-7.0.59_PRPC719
tomcat_pid() {
echo `ps aux | grep $TOMCAT_HOME | grep -v grep | awk '{ print $2 }'`
}
start() {
pid=${tomcat_pid}
if [ -n "$pid" ]
then
echo "Tomcat is already running (pid : $pid )"
else
echo "Starting Tomcat"
sh $TOMCAT_HOME/bin/catalina.sh start &
fi
return 0
}
stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
sh $TOMCAT_HOME/bin/catalina.sh stop
let kwait=10
count=0
until [ `ps -p $pid | grep -c $pid` == '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\nwaiting for processes to exit";
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
echo -n -e "\nkilling processes which didn't stop after 10 seconds"
kill -9 $pid
echo " \nprocess killed manually"
fi
else
echo " Tomcat is not running "
fi
return 0
}
case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac