Restart Tomcat script


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

About Sarath

A Techie from Kochi, India with 8+ years of experience in Linux and Windows server administration. I learn new things almost everyday and I enjoy the fun of learning and sharing my knowledge.