网站502自动重启服务

MY_URL="http://www.youwebsite.com/"
RESULT=`curl -I $MY_URL|grep "HTTP/1.1 502"`
if [ -n "$RESULT" ]; then
/etc/init.d/mysql restart
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart
fi

curl -I 网址后会包含以下信息

HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Tue, 08 Sep 2015 03:35:24 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive

只要grep是否存在HTTP/1.1 (错误码)

就可以在不同返回状态时执行对应操作

posted @ 2015-09-08 11:40  Forward1990  阅读(271)  评论(0编辑  收藏  举报