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 :if [ $? -eq 1 ]
then
echo "Tomcat is down" ; sh /usr/share/tomcat7/bin/startup.sh
fi
*/2 * * * * /path/to/script.sh >/dev/null 2>&1
0 comments: