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