自动重启服务的shell脚本代码
代码如下:
#!/bin/bash if [ ! -f /tmp/down_count ];then echo "0" > /tmp/down_count fi curl -I tomcat-host -o "/tmp/status" >/dev/null 2>&1 code=`awk 'NR==1 {print $2}' /tmp/status` if [ "$[code]" -ge 500 ];then down=`expr $(cat /tmp/down_count) + 1` echo "$down" > /tmp/down_count if [ "$down" -gt 3 ];then if [ ! -f "/tmp/restart_count" ];then echo "0" > /tmp/restart_count fi restart_count=`expr $(cat /tmp/restart_count) + 1` echo "$restart_count" > /tmp/restart_count if [ "$restart_count" -le 2 ];then echo "tomcat down at `date`" >> /tmp/down_info /etc/init.d/tomcat6 restart fi fi else echo "0" > /tmp/down_count echo "0" > /tmp/restart_count fi
脚本实现了,当检测网页状态码大于等于500连续出现3次数,自动重启tomcat6,且只连续重启两次。
相关推荐
huha 2020-10-16
laisean 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
JohnYork 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
wangzhaotongalex 2020-09-22
流年浅滩 2020-10-23
liujianhua 2020-10-22
woaimeinuo 2020-10-21
tufeiax 2020-09-03
laisean 2020-09-01
vvu 2020-09-16
libao 2020-09-16
Yyqingmofeige 2020-08-18
zhushixia 2020-08-17