#!/bin/bash #author:yuxiaoguang#date:2016/5/22echo "Start" url= "/http 127.0.0.1:8090 " curlit () { #echo "?? " curl --connect-timeout 15 --max-time 20 --head --silent "$URL" | grep ' + ' # above 15 is the connection timeout, if the HTTP service that accesses localhost exceeds 15s and still does not respond correctly to the 200 header code, it is determined to be inaccessible. } sleep 10curlit () { #echo "??" curl --connect-timeout 15 --max-time 20 --head --silent "$URL" | grep ' + ' # above 15 is the connection timeout, if the HTTP service that accesses localhost exceeds 15s and still does not respond correctly to the 200 header code, it is determined to be inaccessible. } doit () { if ! curlit; then # An exception occurs if the Tomcat service on localhost does not return 200 headers normally. Execute the following command: # echo "TD" #sleep &NBsp;20 #top -n 1 -b >> /var/log/log.log #kill ' ps -ef|grep java|grep -v grep |awk ' { Print $2} ' > /dev/null 2>&1 # in this statement ps -ef|grep java| Grep -v grep the Java process in the query process to exclude itself from the statement, using awk to find the second column of information, the return state thrown into the black hole. sleep 2 cd /soft/tomcat/bin/ /bin/sh shutdown.shsleep 2/ bin/sh startup.sh #echo "EN" echo $ (date) "Tomcat restart " >> /var/log/log.log # Write Log sleep 60 # Wait after the reboot is complete, and then try again if ! curlit; then # if you still can't access it,: echo "@" echo $ (date) "failed!" >> /var/log/log.log # write Tomcat still restarts the failed log fi sleep 180 fi } sleep 3 # run the script before it starts to work (prevent a miscarriage due to Tomcat not starting after restarting the server) # main loop body doit join crontab Timer Task # Set to detect once every two minutes */2 0 * * * /home/shell/tomcat-check.sh > /dev/null > 2>&1
This article is from the "light-ops commune" blog, please be sure to keep this source http://gugpu.blog.51cto.com/3002132/1775952
The Tomcat process runs a script that monitors and restarts automatically