1

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)

4 Answers 4

6

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
3
  • thanks. the only other thing I had to do was uncomment ping.path and ping.response in php-fpm.d/www.conf Dec 3, 2011 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, 2012 at 15:11
  • 1
    @Synchro - Check the last line on the monit.d script... ;) Oct 25, 2012 at 19:12
1

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).

0

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

Some form of matching "php-fpm"

1
  • 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 Oct 24, 2011 at 10:19
0

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
1
  • nope - no php-fpm.sock anywhere. Oct 24, 2011 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .