1. Description
We need to write a Process Monitoring script to check whether the Tomcat process is stopped or not. If the Tomcat process fails, it is automatically pulled up. Therefore, we have written the following script for reference, I hope to help people in need.
#! /Bin/bashecho "start" url = "http: // 127.0.0.1/###/" curtail() {# echo "?? "Curl -- connect-Timeout 15 -- Max-time 20 -- head -- silent" $ URL "| grep '000000' # The above 15 shows the connection timeout time, if the HTTP service accessing localhost does not correctly respond to the 200 header code after 15 s, it is deemed as inaccessible .} Doit () {If! Curtail; then # If the apache service of localhost does not return 200 headers normally, an exception occurs. Run the following command: # echo "TD" sleep 20 # top-N 1-B>/var/log. logkill 'ps-Ef | grep Java | grep-V grep | awk' {print $2} ''>/dev/null 2> & 1 # ps-Ef in this statement | grep Java | grep-V grep indicates that the Java Process in the query process also excludes its own statement, find the second column of information with awk, and throw the returned status to the black hole. Sleep 2cd/tomcat-6.0.29/bin // bin/sh startup. sh # echo "en" Echo $ (date) "Tomcat restart">/var/log. log # Write log sleep 60 # Wait after restart and try again if! Curtail; then # If the access is still inaccessible, Echo "@" Echo $ (date) "failed !" >/Var/log. log # logs written to Apache that still restart failed fisleep 180fi} sleep 3 # Run the script before the official work starts (to prevent misjudgment caused by Tomcat not started after the server is restarted) # doit