PHP-FPM Monitoring Script Sample

Source: Internet
Author: User
Tags curl fpm log stop script

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!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.