最近后台经常有打不开的情况,和开发沟通过问题,但是开发一直找不到解决办法。
于是就写了一个监控脚本当某个页面无法访问的时候,自动对tomcat进行重启

以下是脚本的具体内容,我使用了nagios nrpe中自带的一款插件进行检测,以下
是具体的检测脚本内容:

vim check_http.sh
#!/bin/bash
DATETIME=`date +"%Y_%m_%d_%H_%M"`
HTTPOK=`/usr/local/nagios/libexec/check_http  -H test.test.com -p 8081 -u /ls.jsp |awk '{print$2}'`
if [ $HTTPOK = "OK:" ];then
echo "$DATETIME HTTP is OK" >>/tmp/http
else
echo "$DATETIME HTTP is CRITICAL" >>/tmp/http
/bin/sh /var/shell/restart_tomcat.sh
fi

restart_tomcat.sh 脚本内容:
#!/bin/bash
. /etc/profile  
tomcatPath_stop="data/tomcat/bin/shutdown.sh"
tomcatPath_start="data/tomcat/bin/startup.sh"
$tomcatPath_stop && sleep 6 && $tomcatPath_start