1 Star 0 Fork 3

镇痛片/shell脚本

forked from xxxx/shell脚本 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
monitor_tomcat.sh 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
xxxx 提交于 2021-04-07 14:13 . add monitor_tomcat.sh.
#!/bin/bash
source /etc/profile
#tomcat path(服务所在目录)
tomcat_home=/opt/gateway
#tomcat start(启动服务脚本)
start_tomcat=$tomcat_home/server.sh
#tomcat PID
tomcatID=$(ps -ef|grep -w tomcat|grep -v 'grep'|awk '{print $2}')
#monitor URL 本机的访问URL(端口号要针对修改)
WebURL=http://localhost:8080/
#输出日志
TomcatMonitorLog=/tmp/TomcatMonitor.log
Monitor()
{
echo "begin monitor tomcat...[$(date +'%F %H:%M:%S')]"
if [ $tomcatID ];then
#check URL status
echo "tomcatID: $tomcatID, go to check URL..."
tomcatServiceCode=$(curl -s -o /dev/null -m 10 --connect-timeout 10 $WebURL -w %{http_code})
if [ $tomcatServiceCode -eq 200 ];then
echo "URLCode: $tomcatServiceCode, tomcat is fine."
else
echo "tomcat is bad...URLCode: $tomcatServiceCode, error.log was print to $GetUrlInfo"
echo "restart tomcat..."
kill -9 $tomcatID
sleep 3
cd $tomcat_home
sleep 1
nohup ${start_tomcat} > $tomcat_home/nohup.out 2>&1 &
fi
else
echo "tomcat PID is not exists!restart tomcat..."
cd $tomcat_home
sleep 1
nohup ${start_tomcat} > $tomcat_home/nohup.out 2>&1 &
fi
echo "____------_____-----_____"
}
Monitor>>$TomcatMonitorLog
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/itboge/shell-script.git
[email protected]:itboge/shell-script.git
itboge
shell-script
shell脚本
master

搜索帮助