##check the status of tomcat
is_tomcat_running(){
PID=$(cat $TOMCAT/conf/catalina.pid 2>&1)
if [ "x$PID" != "x" ]&& kill -0 $PID 2>/dev/null; then
_status=0 #echo "tomcat already running"
else
_status=1 #echo "tomcat is not running"
fi
return $_status
}
How to stop the Tomcat with bash script?
stop() {
pid==$(cat $TOMCAT/conf/catalina.pid 2>&1)
if [ -n "$pid" ]
then
echo -e "\e[00;31mStoping Tomcat\e[00m"
#/bin/su -p -s /bin/sh $TOMCAT_USER
sh $CATALINA_HOME/bin/shutdown.sh
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
echo -n -e "\n\e[00;31mkilling processes didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
terminate
fi
else
echo -e "\e[00;31mTomcat is not running\e[00m"
fi
return 0
}
Note: We need to kill/terminate the tomcat if it is failed to shutdown with in the given period of time& we need to clear the PID.