Here is just short script that restarts tomcat when it wrizes. It happens to our prod during peak load. You need to place inder webapps/ROOT directory a file isalive.html with one word ‘YES’ inside. Or alternatively modify a script and access default index.jsp.
#!/bin/sh
HOST=127.0.0.1
PORT=8080
#infinite loop
while [ 1 ]
do
#try to access tomcat's page
RES=`wget -O - -o /dev/null --proxy=off http://${HOST}:${PORT}/isalive.html | awk '{ print $1 }'`
echo got ${RES}
#decide on reply
if [ "$RES" = "YES" ]
then
echo tomcat is responding on $HOST:$PORT
else
echo tomcat seems to be dead.
echo Killing...
for thepin in `ps -Af | grep -v grep | grep tomcat | grep catalina | awk '{ print $2 }'`
do
kill -9 ${thepin}
done
echo Starting...
sudo -u tomcat /usr/local/tomcat/bin/startup.sh
fi
sleep 60
done
Advertisements
September 26, 2006 at 11:29 am |
Thanks for the script. I’ve used it with some improvements relevant to my environment.
I’m planning to add ability of monitoring multiple web apps and automatical restarting of single web app through tomcat manager. When it will be done I’m going to publish it.