Automatic monitoring tomcat service, when the service tommcat hang automatically restart
First, the script content
[root @ localhost] # CAT /root/autoCheck.sh ! # / bin / bash startTomcat = / usr / local / Tomcat-7 / bin / startup.sh tomcatLog = / tmp / tomcatLog tomcatID = `PS -ef | grep Tomcat -7 | grep -w '. 7-Tomcat' | grep -v 'grep' | WC -l` Monitor () { #while to true; do # tomcatID = `PS -ef | grep-Tomcat. 7 | grep -w 'Tomcat -7 '| grep -v' grep ' | WC -l` echo "[info] ... begin monitoring Tomcat [$ (DATE +'% F.% H:% M:% S ')]" IF [$ tomcatID -lt 1 ]; the then echo "! [error] process does not exist tomcat tomcat start automatically restart ..." echo "[info] $ startTomcat, please wait ..." Trail 3 $ start tomcat echo "[info] Service started successfully ..." fi echo "==================================== ================== " #SLEEP 1 #done } Monitor >> $ tomcatLog
analysis:
1) define tomcat service startup directory startTomcat
2) define the log output directory tomcatLog
3) tomcat process ID of the query, the presence of the process ID by wc -l statistics, then there is greater than 1, less than 1 does not exist
4) determine whether there is a tomcat service process, less than a service does not exist, sleep three seconds to restart the tomcat service, and start the output information to the log file
Second, set the scheduled task
It is set to perform a monitoring script every minute
[root@localhost ]# crontab -l
*/1 * * * * /root/autoCheck.sh