Scripting code
| The code is as follows |
Copy Code |
if [-e/var/lock/subsys/502]
Then
Killall-9 Curl 2>/dev/null
Killall-9 PHP-FPM 2>/dev/null
Killall-9 php-cgi 2>/dev/null
Service PHP-FPM Start >/dev/null
echo "[' Date + '%h%d%T '] php-fpm died with no response, all processes restarted" >>log.txt
Else
touch/var/lock/subsys/502
If [' Curl--connect-timeout 5-i http://www.111cn.net/2>/dev/null | grep ' 502 Bad Gateway '-C '!= ' 0 ']
Then
Killall-9 PHP-FPM 2>/dev/null
Killall-9 php-cgi 2>/dev/null
Service PHP-FPM Restart >/dev/null
echo "[' Date + '%h%d%T '] php-fpm died with 502 Bad gateway, all processes restarted" >>log.txt
Fi
Rm-f/var/lock/subsys/502
Fi
|
The
script needs to have curl installed, the only place that needs to be modified is the URL that is involved in it, that is, through this address to determine whether the server is faulted. The script is executed every 1 minutes by crontab. The service automatically restarts when the fastcgi cannot be answered.