天天看點

502 Bad Gateway自動重新開機腳本

一個簡單的腳本,用來監控502的,如果遇到502,自動重新開機PHP程序。适用于LNMP環境。

建立

php.sh

檔案,存放于

/root

或其它目錄:

#!/bin/bash
MY_URL="http://www.moerats.com/"
RESULT=`curl -I $MY_URL|grep "HTTP/1.1 502"`
if [ -n "$RESULT" ]; then
        /etc/init.d/php-fpm restart
fi           

複制

給予可執行權限:

chmod +x /root/php.sh           

複制

通過 crontab 設定自動運作:

crontab -e
* * * * * /root/php.sh           

複制