The Tomcat process runs a script that monitors and restarts automatically

Source: Internet
Author: User

#!/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

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.