Tomcat Self-starter script

Source: Internet
Author: User
Tags log log

    1. Vim selfrestart.sh #创建自启动脚本, add the following to the file, the value of the script may change

#!/bin/sh# func: Automatically monitor tomcat scripts and perform restart operations # author:reed# date:12/09/2012#  define environment variables path=/usr/local/ sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.5.0_11/binexport java_home=/usr/java/ Jdk1.7.0_79export classpath= $JAVA _home/lib: $JAVA _home/lib/tools.jarexport path= $PATH: $JAVA _home/bin#  DEFINE#  Get Tomcat process idtomcatid=$ (ps -ef |grep tomcat_1 |grep -w  ' Tomcat _1 ' |grep -v  ' grep ' |awk  ' {print $2} ') # tomcat boot program (note the path that Tomcat actually installs) starttomcat=/usr/ local/tomcat_1/bin/./startup.sh#  define the page address to monitor weburl=http://127.0.0.1#  log output getpageinfo=/tmp/ Tomcatmonitor.infotomcatmonitorlog=/tmp/tomcatmonitor.logmonitor ( ) {  echo  "[INFO] Start monitoring tomcat_1 ... [$ (date + '%f %h:%m:%s ')] "   tomcatservicecode=$ (curl -i -m 10 -o  /dev/null -s -w %{http_code} "\ n"    $WebUrl)     if [   $TomcatServiceCode -eq 200 ];       then         echo  "[INFO] page return code for $TOMCATSERVICECODE,TOMCAT is running, test page normal ..."     elif  [ ! -n  $TomcatID  ];        then         kill -9  $TomcatID   #  Kill the original tomcat_1 process        else        echo  " tomcat stop running, the page return code is $TomcatServiceCode, restart after 3 seconds "| mail -s " Tomcat status " [email protected]         echo  " tomcat stop running, the page return code is $tomcatservicecode,3 seconds to start restarting" |  mail -s  "Tomcat status"  [email protected]         echo  "[Info]tomcat stop operation, page return code is $tomcatservicecode "           $StartTomcat  Fi}monitor>> $TomcatMonitorLog 

2.crontab-e #编辑定时任务,

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/2D/wKioL1cV6aPQteEpAAA9H_pqEAU146.png "title=" Qq20160419161409.png "alt=" Wkiol1cv6apqteepaaa9h_pqeau146.png "/> is performed once per minute.

3. View our defined/tmp/tomcatmonitor.log log file, we can see the specific situation, can be tested, the Tomcat will be stopped. Tomcat will start automatically after 1 minutes and can also view messages.

This article from "Cheng Xiao Bai" blog, declined reprint!

Tomcat Self-starter script

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.