linux tomcat宕机自动启动脚本,tomcat宕机自动重启脚本「建议收藏」

2022-09-15 10:34:46 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

#!/bin/bash

# 获取tomcat进程ID /usr/share/tomcat

TomcatID=(ps -ef |grep tomcat |grep -w ‘tomcat‘|grep -v ‘grep‘|awk ‘{print 2}‘)

# tomcat启动程序(这里注意tomcat实际安装的路径)

#StartTomcat=/usr/local/tomcat/bin/startup.sh

#yum安装后启动tomcat指令:systemctl start tomcat

# 定义要监控的页面地址

WebUrl=http://localhost:8080/dist/

# 日志输出

TomcatMonitorLog=/usr/share/tomcat/logs/TomcatMonitor.log

Monitor()

{

echo “[info]开始监控tomcat…[$(date ‘%F %H:%M:%S‘)]”

if [[ $TomcatID ]];then # 这里判断TOMCAT进程是否存在

echo “[info]当前tomcat进程ID为:$TomcatID,继续检测页面…”

# 检测是否启动成功(成功的话页面会返回状态”200″)

TomcatServiceCode=(curl -I -m 10 -o /dev/null -s -w %{http_code} WebUrl)

if [ $TomcatServiceCode -eq 200 ];then

echo “[info]页面返回码为$TomcatServiceCode,tomcat启动成功,测试页面正常……”

else

echo “[error]tomcat页面出错,请注意……状态码为TomcatServiceCode,错误日志已输出到GetPageInfo”

echo “[error]页面访问出错,开始重启tomcat”

kill -9 $TomcatID # 杀掉原tomcat进程

sleep 3

#rm -rf $TomcatCache # 清理tomcat缓存

systemctl start tomcat

fi

else

echo “[error]tomcat进程不存在!tomcat开始自动重启…”

echo “[info]tomcat starting,请稍候……”

#rm -rf $TomcatCache

systemctl start tomcat

fi

echo “——————————“

原文:https://www.cnblogs.com/jin-521/p/11436353.html

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/163645.html原文链接:https://javaforall.cn

0 人点赞