Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm struggling to find a monit config for php-fpm that works.

This is what I've tried:

### Monitoring php-fpm: the parent process.
check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
  group phpcgi # phpcgi group
  start program = "/etc/init.d/php-fpm start"
  stop program  = "/etc/init.d/php-fpm stop"
  ## Test the UNIX socket. Restart if down.
  if failed unixsocket /var/run/php-fpm.sock then restart
  ## If the restarts attempts fail then alert.
  if 3 restarts within 5 cycles then timeout
  depends on php-fpm_bin
  depends on php-fpm_init

## Test the php-fpm binary.
check file php-fpm_bin with path /usr/sbin/php-fpm
   group phpcgi
   if failed checksum then unmonitor
   if failed permission 755 then unmonitor
   if failed uid root then unmonitor
   if failed gid root then unmonitor

## Test the init scripts.
check file php-fpm_init with path /etc/init.d/php-fpm
   group phpcgi
   if failed checksum then unmonitor
   if failed permission 755 then unmonitor
   if failed uid root then unmonitor
   if failed gid root then unmonitor

But it fails because there is no php-fpm.sock (Centos 6)

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

I´m using the ping.path directive in php-fpm to check if it´s working...

and configured it on nginx.conf (i down´t know if it´s your setup)

location /ping {
    access_log     off;
    allow          127.0.0.1;
    deny           all;
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
    include        fastcgi_params;
}

On monit.d

check process php-fpm.www with pidfile /var/run/php-fpm/php-fpm.pid
  group php-fpm
  start program = "/etc/init.d/php-fpm start"
  stop program  = "/etc/init.d/php-fpm stop"
  if failed host localhost port 80 protocol http
     and request '/ping'
     with timeout 20 seconds for 5 cycles
     then restart
  ## If the restarts attempts fail then alert.
  if 3 restarts within 5 cycles then timeout
  depends on php-fpm_bin
  depends on php-fpm_init
  depends on nginx
share|improve this answer
    
thanks. the only other thing I had to do was uncomment ping.path and ping.response in php-fpm.d/www.conf –  Adam Jimenez Dec 3 '11 at 9:13
    
The problem with this approach is that if nginx is down, monit will kill PHP-FPM, possibly making whatever problem you're having worse. –  Synchro Oct 25 '12 at 15:11
    
@Synchro - Check the last line on the monit.d script... ;) –  Marcelo Bittencourt Oct 25 '12 at 19:12
add comment

As far as I could see, the only difference between php5-fpm and other processes (like nginx) is that its pid file doesn't contain a newline character. Maybe that's the problem. In any case, my solution is uglier but it also works nicely: I just check "process php-fpm with pidfile /var/run/php5-fpm.sock" directly (while trying to find a fix to this bug).

share|improve this answer
add comment

Have you considered using monit's process pattern matching along with the existing daemon start and stop?

Some form of matching "php-fpm"

share|improve this answer
    
well it's already tracking the process from the pid file is it not? I was thinking the answer might be to open a http page and look for "bad gateway" - but no idea how to do that :s –  Adam Jimenez Oct 24 '11 at 10:19
add comment

Is there php-fpm.sock file in /var/run/php-fpm/php-fpm.sock? If there is, then modify this line

if failed unixsocket /var/run/php-fpm.sock then restart

wit

if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart
share|improve this answer
    
nope - no php-fpm.sock anywhere. –  Adam Jimenez Oct 24 '11 at 10:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.