tomcat守护进程脚本
tomcat守护进程脚本1--------------------------------------------------
TomcatID=`ps -ef|grep "/home/admin/tomcat"|grep -v 'grep'|head -1|awk '{print $2}'`
StartTomcat= /home/admin/tomcat/bin/startup.sh
Weburl=http://localhost:8899/app/#!
TomcatMonitorlog=/home/admin/tomcat/script/tomcatMonitor.log
statusFile=/home/admin/tomcat/script/status.txt
Monitor(){
while :
do
if [ $TomcatID ];then
echo "================="
echo $(date +"%Y-%m-%d %T")
echo "The TomcatID is $TomcatID"
TomcatServerCode=`curl -I $Weburl > $statusFile`
Status=`cat $statusFile|head -1|awk '{print $2}'`
if [ $Status -eq 200 ];then
echo "Tomcat is ok"
else
echo "Tomcat Is Error 》 Kill Tomcat"
kill -9 $TomcatID
sleep 10
echo "Tomcat Is Error 》 Restart Tomcat"
$StartTomcat
fi
fi
echo "OVER"
sleep 300
done
}
Monitor >> $TomcatMonitorlog
执行方案------------------------------------------------
nohup ./monitor_tomcat2.sh &
*******************************************************
*******************************************************
tomcat守护进程脚本2------------------------------------------------------
TomcatID=`ps -ef|grep "/home/admin/tomcat"|grep -v 'grep'|head -1|awk '{print $2}'`
StartTomcat= /home/admin/tomcat/bin/startup.sh
Weburl=http://localhost:8899/app/#!
TomcatMonitorlog=/home/admin/tomcat/script/tomcatMonitor.log
statusFile=/home/admin/tomcat/script/status.txt
Monitor(){
if [ $TomcatID ];then
echo "================="
echo $(date +"%Y-%m-%d %T")
echo "The TomcatID is $TomcatID"
TomcatServerCode=`curl -I $Weburl > $statusFile`
Status=`cat $statusFile|head -1|awk '{print $2}'`
if [ $Status -eq 200 ];then
echo "Tomcat is ok"
else
echo "Tomcat Is Error 》 Kill Tomcat"
kill -9 $TomcatID
sleep 10
echo "Tomcat Is Error 》 Restart Tomcat"
$StartTomcat
fi
fi
echo "OVER"
}
Monitor >> $TomcatMonitorlog
执行方案------------------------------------------------去掉脚本中的while,然后定时执行
添加定时任务中
sudo crontab -e
将该脚本添加到定时任务
*/1 * * * * /home/script/monitor.sh