#!/bin/bash#1, determine if the service is available 2, do not use restart TOMCAT#*/30 * * * */home/wsm/restart.sh >>/home/wsm/restart.log# Stop tomcatfunction Killtomcat () {pid= ' ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk ' {print $} ' if [-n ' $pid '];THENPS-EF | gre P "/home/wsm/bin/tomcat" | Grep-v grep | awk ' {print $} ' | Xargs kill-9fisleep 10echo ' Date "+%y-%m-%d%h:%m:%s" ' "| Killd Tomcat "} #启动tomcatfunction Starttomcat () {pid= ' Ps-ef | grep "/home/wsm/bin/tomcat" | Grep-v grep | awk ' {print $} ' if [-n ' $pid '];thenps-ef | grep "/home/wsm/bin/tomcat" | Grep-v grep | awk ' {print $} ' | Xargs kill-9sleep 10else/home/wsm/bin/startup.sh echo ' date ' +%y-%m-%d%h:%m:%s ' ' | Start Tomcat End "Fi}ctime= ' Date" +%y-%m-%d%h:%m:%s "" Export java_home= "/usr/java/jdk1.7.0_21" #export path= "$JAVA _ Home/bin: $PATH "Export path="/usr/java/jdk1.7.0_21/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/ Sbin:/bin:/usr/sbin:/usr/bin:/root/bin "Export lang=" en_US. UTF-8 "#获取本机IPlocalip = ' ifconfig | grep ' inet addr: ' | Grep -V ' 127.0.0.1 ' | Cut-d:-f2 | awk ' {print '} ' #调用本机应用服务, get the HTTP return code status_code= '/usr/bin/curl-o/dev/null-s-M--connect-timeout 30-w%{http_code} $localip: 8080/wsmmeasure/str/report/performancereport ' echo $ctime | Status_code= "$STATUS _code# if the return code is not 200 restart Tomcatif [$STATUS _code-ne];thenecho" status_code= "$STATUS _code# Killtomcatecho ' export ' >>/home/wsm/restart.logecho ' date ' +%y-%m-%d%h:%m:%s ' ' |100001|killtomcat ' # Starttomcatecho ' Date ' +%y-%m-%d%h:%m:%s "'" |100002|starttomcat "fi
Restarting the Tomcat shell