Server monitoring is necessary, recently found that the server sometimes fastcgi will stop responding, in order to allow him to work properly (when the discovery stopped, restart), because there is the following monitoring script. < This article is transferred from Www.opsers.org, since others have written, I do not bother to write. >
The script works by:
Access the site through the Curl command, restarting fastcgi when the returned status result is not 200.
Because the site home content more, in order to reduce the burden on the server, we can specify a PHP page, the page content can write a code of PHP, such as:
< php echo "Hello word!"; ?>
Chkfastcgi.sh content is as follows
#!/bin/bash
#监控的网页地址
Url= "http://www.opsers.org/bash.php"
#fastcgi启动/reboot/Stop script path
prog=/usr/local/php/sbin/php-fpm
#fastcgi重启记录日志文件
Log=/var/log/php-fpm/restart.log
#返回结果正常记录日志
Log2=/var/log/php-fpm/check.log
#时间
Time= ' Date '
#状态检查
status=$ (curl-s--head "$url" | awk '/http/{print $} ')
#如果不是200, write to the log, and then reboot
If ["$status"!= "200"]; Then
echo "Restart php-cgi at ${time}" >> $LOG
$PROG restart
#如果你想发邮件, just write the email command at this location.
Else
#记录正常状态的日志
echo "PHP CGI is running ${time}" >> $LOG 2
# If you want him to do nothing, put the above "echo" PHP CGI is running ${time} ">> $LOG 2"
Delete, replace with the following colon #:
Fi
The last is to add the script to the Task Scheduler task, every once in a while (Remember to add execution permissions AH), this time can be based on their own server situation, the appropriate settings
*/1 * * * */bin/bash/chkfastcgi.sh
Finally, to remind everyone that the system must have curl this command oh, otherwise, oh, you cry!! Why, then?
It's like this, how your system does not curl this command, of course, the previous script can not find 200 state, without this state, will restart, imagine, if you set every minute to perform once, then, your service will be restarted every minute!! Oh!! Pay attention!!