Script for monitoring and automatically restarting Tomcat processes in Linux

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.