Sunday 30 June 2013

Restart Tomcat script

Posted by Sarath On Sunday, June 30, 2013 No comments

Here is a simple script that is tested on CentOS and Ubuntu. It will work on all other UNIX like platforms. You can make modifications to this script to restart any other services, for example apache. You can also use pgrep command instead of pidof command.

# vi
script.sh
  ##Restart Tomcat##
pidof java
if [ $? -eq 1 ]
then 
echo "Tomcat is down" ; sh /usr/share/tomcat7/bin/startup.sh
fi
And add a cronjob as follows :

*/2 * * * * /path/to/script.sh >/dev/null 2>&1

0 comments: