#! /bin/bash
# set -e
# 设置Tomcat脚本目录
tomcat_bin=/home/apache-tomcat-8.5.23/bin
# 输出当前时间
echo "===== `date +%c` ====="
# 取得Tomcat的进程ID
tomcat_pid=`ps aux | grep tomcat | grep java | grep -v grep | grep -v retomcat | awk '{print $2}'`
if [ -z $tomcat_pid ]
then
#echo "Tomcat is not running."
exit
fi
#echo "Tomcat PID is $tomcat_pid"
# 取得网站首页面HTTP返回状态码
result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} 127.0.0.1:8080/web/index?city=china`
# 判断HTTP状态码是否正常
if [ $result_code = "200" ]
then
#echo "Tomcat is OK!"
exit
fi
# 正常关闭Tomcat
echo "Tomcat will shutdown."
$tomcat_bin'/shutdown.sh'
sleep 2
# 判断是否正常关闭
tomcat_pid=`ps aux | grep tomcat | grep java | grep -v grep | grep -v retomcat | awk '{print $2}'`
if [ -n "$tomcat_pid" ]
then
sleep 2
# 强制结束Tomcat进程
echo "Tomcat(PID:$tomcat_pid) will be killed."
kill -9 $tomcat_pid
fi
sleep 2
# 启动Tomcat
echo "Tomcat will startup."
$tomcat_bin'/startup.sh'
监控TOMCAT,确保正常运行,防止卡死
最新推荐文章于 2022-03-16 23:08:15 发布