监控tomcat服务自动重新启动shell脚本

具体脚本代码如下:



#!/bin/sh
##################################################
#this script is monitoring tomcat 
###########################



return=`curl -s -w %{http_code} -o /dev/null http://www.test.com`

echo $return

javapid=`ps aux|grep java|grep -v grep|grep tomcat|awk '{print $2}'`

echo $javapid

if [ $return -eq 502 ];then
        
    echo "service Is bad !"

 if [ ! -n "$javapid" ]; then
    echo "no java process "
  /bin/sh /opt/server/tomcatSearchWeb/bin/startup.sh 
  echo "Tomcat restart"
 else
    echo "has a java process"
  kill -9 $javapid
  sleep 5
  /bin/sh /opt/server/tomcatSearchWeb/bin/startup.sh 
  echo "Tomcat restart"
 fi 

else
 echo "service Is ok"
fi




你可能感兴趣的:(shell脚本编程,LINUX技术)