Watchdog for tomcat

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.


#infinite loop
while [ 1 ]
	#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" ]
		echo tomcat is responding on $HOST:$PORT
		echo tomcat seems to be dead.
		echo Killing...
		for thepin in `ps -Af | grep -v grep | grep tomcat | grep catalina | awk '{ print $2 }'`
			kill -9 ${thepin}
		echo Starting...
		sudo -u tomcat /usr/local/tomcat/bin/

sleep 60

One Response to “Watchdog for tomcat”

  1. Vitaly Says:

    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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: