tomcat 监控脚本

ps -ef |grep tomcat |grep -w 'atlassian'|grep -v 'grep'|awk '{print $2}'

curl -s -o /dev/null -m 10 --connect-timeout 10 http://127.0.0.1:8090/login.action -w %{http_code}

 

#!/bin/sh
# function:自动监控wiki进程,挂了就执行重启操作
# author:pomme
# DEFINE

# 获取tomcat PPID
WikiID=$(ps -ef |grep tomcat |grep -w 'atlassian'|grep -v 'grep'|awk '{print $2}')


# 定义要监控的页面地址
WebUrl=http://127.0.0.1:8090/login.action

# 日志输出
GetPageInfo=/dev/null
MonitorLog=/tmp/Monitor.log

Monitor()
{
echo "[info]开始监控tomcat...[$(date +'%F %H:%M:%S')]"
if [ $WikiID ];then
echo "[info]tomcat进程ID为:$WikiID."
# 获取返回状态码
ServiceCode=$(curl -s -o $GetPageInfo -m 10 --connect-timeout 10 $WebUrl -w %{http_code})
if [ $ServiceCode -eq 200 ];then
echo "[info]返回码为$ServiceCode,wiki启动成功,页面正常."
else
echo "[error]访问出错,状态码为$ServiceCode,错误日志已输出到$GetPageInfo"
echo "[error]开始重启tomcat"
/etc/init.d/confluence restart
fi
else
echo "[error]进程不存在!tomcat自动重启..."
echo "[info]$StartTomcat,请稍候......"
/etc/init.d/confluence restart
fi
echo "------------------------------"
}
Monitor>>$MonitorLog

posted @ 2018-05-16 15:31  Pomme_king  阅读(168)  评论(0编辑  收藏  举报