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.



#!/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

About these ads

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: