Monit configuration for php-fpm
Asked Answered
M

6

10

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

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

Meistersinger answered 21/10, 2011 at 8:25 Comment(0)
A
3

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;
}
Audra answered 26/10, 2011 at 22:53 Comment(0)
R
15

For anyone else with this problem on Centos 6, the php-fpm socket is in /var/run/php-fpm/php-fpm.sock

Hence final config would be like so:

check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
  group phpcgi #change accordingly
  start program = "/etc/init.d/php-fpm start"
  stop program  = "/etc/init.d/php-fpm stop"
  if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart
  if 3 restarts within 5 cycles then timeout
Ryon answered 19/6, 2012 at 10:47 Comment(0)
K
6

Instead of:

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

you may try:

if failed port 9000 type TCP then restart

It does not require editing lighttpd/nginx config as in the location /ping case.

My /etc/monit/conf.d/php-fpm.conf on Ubuntu looks like this:

check process php-fpm with pidfile /var/run/php5-fpm.pid
  stop program = "/sbin/start-stop-daemon --stop --pidfile /var/run/php5-fpm.pid"
  start program  = "/sbin/start-stop-daemon --start --pidfile /var/run/php5-fpm.pid --exec /usr/sbin/php5-fpm"
  if failed port 9000 type TCP then restart
Kinny answered 18/6, 2012 at 8:23 Comment(0)
A
3

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;
}
Audra answered 26/10, 2011 at 22:53 Comment(0)
K
1

Here is a way of checking php-fpm via a TCP connection (which is more reliable than a simple .pid):

# Empty FastCGI request
if failed port 8101
  # Send FastCGI packet: version 1 (0x01), cmd FCGI_GET_VALUES (0x09)
  # padding 8 bytes (0x08), followed by 8xNULLs padding
  send "\0x01\0x09\0x00\0x00\0x00\0x00\0x08\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00"
  # Expect FastCGI packet: version 1 (0x01), resp FCGI_GET_VALUES_RESULT (0x0A)
  expect "\0x01\0x0A"
  timeout 5 seconds
then restart

Source: http://richard.wallman.org.uk/2010/03/monitor-a-fastcgi-server-using-monit/

Konstanz answered 20/3, 2017 at 18:5 Comment(0)
R
1

This is work for me

 check process php5-fpm with pidfile /var/run/php5-fpm.pid
  start program = "/usr/sbin/service php5-fpm start" with timeout 60 seconds
  stop program = "/usr/sbin/service php5-fpm stop"
  if cpu > 60% for 2 cycles then alert
  if cpu > 90% for 5 cycles then restart
  if 3 restarts within 5 cycles then timeout
  group server
Rollicking answered 19/3, 2018 at 4:50 Comment(0)
P
0

This is on my debian 7 running nginx and php5-fpm;

check process php5-fpm with pidfile /var/run/php5-fpm.pid
group php #change accordingly
start program = "/etc/init.d/php5-fpm start"
stop program  = "/etc/init.d/php5-fpm stop"
if failed unixsocket /tmp/php-fpm.sock then restart
if 3 restarts within 5 cycles then timeout
Precipitin answered 19/4, 2013 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.