tomcatID=`ps -ef |grep tomcat |grep -v 'grep'|awk '{print $2}'`
tomcatCount=`ps -ef|grep tomcat |grep -v 'grep' |wc -l`
startTomcat=/root/tomcat/apache-tomcat-7.0.64/bin/startup.sh
tomcatCache=/root/tomcat/apache-tomcat-7.0.64/work
http_code=200
if [ $tomcatCount -gt 0 ]
then
statusCode=$(curl -o /dev/null -I -s -w "${http_code}" "${hostUrl}")
echo $statusCode
if [ $statusCode -eq "200" ];then
echo "server is OK."
else
echo "服务不可用,重新启动服务"
kill -9 $tomcatID # 杀掉原tomcat进程
sleep 3
rm -rf $tomcatCache #
$startTomcat
fi
else
echo "进程不存在,重新启动服务"
rm -rf $tomcatCache
$startTomcat >>/tmp/error.log
fi