Use Shell in LINUX to automatically monitor tomcat and restart

Source: Internet
Author: User
In LINUX, Shell is used to automatically monitor tomcat and restart the tomcat instance. 01 #! /Bin/sh0203 # func: automatically monitors tomcat scripts and restarts www.2cto. com04 # author: danny05 # date: 02/20/201306 # DEFINE0708 # get the tomcat process IDwww .... in LINUX, Shell is used to automatically monitor tomcat and restart the tomcat instance. 01 #! /Bin/sh02 03 # func: automatically monitors tomcat scripts and performs restart operations www.2cto.com 04 # author: danny05 # date: 02/20/201306 # DEFINE07 08 # get tomcat process ID www.2cto.com 09 TomcatID =id (ps-ef | grep tomcat | grep-w'dw \/apache-tomcat-
7.0.34 \/Conf' | grep-v 'grep' | awk '{print $2}') 10 11 # tomcat startup program (pay attention to the actual installation path of tomcat) 12 StartTomcat =/home/dw/apache-tomcat-7.0.34/bin/startup. sh13 # TomcatCache =/usr/apache-tomcat-5.5.23/work14 15 # define the page address to be monitored 16 WebUrl = http://haoyayi.eyar. com17 18 # Log output 19 GetPageInfo =/dev/null20TomcatMonitorLog =/tmp/TomcatMonitor. log21 22 Monitor () 23 {24 echo "[info] start monitoring tomcat... [$ (date + '% F % H: % M: % S')] "25 if [$ TomcatID]; then # determine whether the TOMCAT process exists 26 echo "[info] The current tomcat process ID is: $ TomcatID. continue to check the page... "27 # check whether the startup is successful (if successful, the page will return the status" 200 ") 28 TomcatServiceCode = $ (curl-s-o $ GetPageInfo-m 10 --
Connect-timeout 10 $ WebUrl-w % {http_code}) 29 if [$ TomcatServiceCode-eq 200]; then30 echo "[info] Page return code $ TomcatServiceCode, tomcat started successfully,
The test page is normal... "31 else32 echo" [error] tomcat page error. Please note that the status code is $ TomcatServiceCode,
Error log output to $ GetPageInfo "33 echo" [error] Page access error, restart tomcat "34 # kill-9 $ TomcatID # kill the original tomcat process 35 # sleep 336 # rm-rf $ TomcatCache # clear tomcat cache 37 # $ StartTomcat38 fi39 else40 echo" [error] The tomcat process does not exist! Tomcat starts automatic restart... "41 echo" [info] $ StartTomcat, please wait ...... "42 # rm-rf $ TomcatCache43 # $ StartTomcat44 fi45 echo" ---------------------------- "46} 47 Monitor> $ TomcatMonitorLog

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.