服務返回異常5次就重啟
阿新 • • 發佈:2020-12-30
1.1
#!/bin/bash restart=0 time=0 while true do for i in `cat /opt/check_status/monitor_url.txt` do echo $i sleep 5 timeout 10 ssh appuser@172.36.35.224 " curl $i " > /tmp/portal.txt rc=`egrep -c 'code":"0","desc":"成功","data' /tmp/portal.txt` if [[ $rc -ne 1 ]] then date echo"$i is down" if [[ $restart -eq 0 ]];then let time++ fi else restart=0 fi if [[ $time -gt 5 ]];then echo 'restart mgr1 ...........................' curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cc2fwo85-70db-4shi7-8c26-e8f2sb9d4d6' \ -H 'Content-Type: application/json' \ -d ' { "msgtype": "markdown", "markdown": { "content": "<font color=\"warning\">'$i'</font> prod selfhealing after 5 alerts " } }' /bin/bash /opt/update/kill-tomcat.sh /bin/bash /opt/update/start-tomcat.sh time=0 restart=1 sleep 60 fi done sleep 50 done