#!/bin/sh
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export JAVA_HOME=/usr/java/jdk1.6.0_37
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
TomcatID=$(ps -ef | grep tomcat|grep -w 'tomcat-7.0.42'|grep -v grep|awk '{print $2}')
StartTomcat=/opt/soft/tomcat-7.0.42-linux-pro/bin/startup.sh
TomcatCache=/opt/soft/tomcat-7.0.42-linux-pro/work
WebUrl=https://localhost/
GetPageInfo=/tmp/TomcatMonitor.Info
TomcatMonitorLog=/tmp/TomcatMonitor.log
Monitor()
{
echo "[info]开始监控tomcat...[$(date +'%F %H:%M:%S')]"
if [ $TomcatID ];then
TomcatServiceCode=$(curl -o $GetPageInfo -s -m 10 --connect-timeout 10 -w %{http_code} -k $WebUrl)
if [ $TomcatServiceCode -eq 200 ];then
echo "[info]页面返回码为$TomcatServiceCode,tomcat启动成功,测试页面正常......"
else
echo "[error]tomcat页面出错,请注意......状态码为$TomcatServiceCode,错误日志已输出到$GetPageInfo"
echo "[error]页面访问出错,开始重启tomcat"
kill -9 $TomcatID
sleep 3
rm -rf $TomcatCache
$StartTomcat
fi
else
echo "[error]tomcat进程不存在!tomcat开始自动重启..."
echo "[info]$StartTomcat,请稍候......"
rm -rf $TomcatCache
$StartTomcat
fi
}
Monitor>>$TomcatMonitorLog
时间: 2024-10-27 17:02:04