重启tomcat shell
#!/bin/bash #1、判断服务是否可用 2、不可用重启tomcat #*/30 * * * * /home/wsm/restart.sh >> /home/wsm/restart.log #停止tomcat function killTomcat(){ pid=`ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}'` if [ -n "$pid" ];then ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9 fi sleep 10 echo `date "+%Y-%m-%d %H:%M:%S"` "| killd tomcat " } #启动tomcat function startTomcat(){ pid=`ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}'` if [ -n "$pid" ];then ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9 sleep 10 else /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" #获取本机IP localip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'` #调用本机应用服务,获取http返回码 STATUS_CODE=`/usr/bin/curl -o /dev/null -s -m 13 --connect-timeout 30 -w %{http_code} $localip:8080/WSMMeasure/str/report/performancereport` echo $ctime " | STATUS_CODE= " $STATUS_CODE #如果返回码不是200 重启tomcat if [ $STATUS_CODE -ne 200 ];then echo "STATUS_CODE=" $STATUS_CODE #killTomcat echo `export` >> /home/wsm/restart.log echo `date "+%Y-%m-%d %H:%M:%S"`"|100001|killtomcat" #startTomcat echo `date "+%Y-%m-%d %H:%M:%S"`"|100002|starttomcat" fi
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。