Question

I recently set up Ubuntu Natty with PHP5-FPM, Gearman, and Supervisor. I've edited my Supervisord config to run a Gearman worker.

[program:gearman] 
command=/usr/bin/php php_gearman_worker.php
numprocs=1 
directory=/root/sandbox
stdout_logfile=/root/sandbox/supervisord.log 
environment=GEARMAN_USER=gearman 
autostart=true
autorestart=true
user=gearman

Here's the relevant info (showing only gearmand and php processes) when I lsof -i -P before I run supervisord:

COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gearmand  29314  gearman    6u  IPv4 328139      0t0  TCP localhost:4730 (LISTEN)    

And here's what I get when I lsof -i -P after I /etc/init.d/supervisor stop && /etc/init.d/supervisor start.

COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gearmand  29314  gearman    6u  IPv4 328139      0t0  TCP localhost:4730 (LISTEN)
gearmand  29314  gearman   11u  IPv4 328206      0t0  TCP localhost:4730->localhost:39072 (ESTABLISHED)
php       29571  gearman    4u  IPv4 329744      0t0  TCP localhost:39072->localhost:4730 (ESTABLISHED)

I don't see any listing for supervisord itself, should I see supervisord as one the commands?!

Anyway, when I stop and start (or restart) supervisord again:

COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gearmand  29314  gearman    6u  IPv4 328139      0t0  TCP localhost:4730 (LISTEN)
gearmand  29314  gearman   11u  IPv4 328206      0t0  TCP localhost:4730->localhost:39072 (ESTABLISHED)
gearmand  29314  gearman   12u  IPv4 329754      0t0  TCP localhost:4730->localhost:51570 (ESTABLISHED)
php       29571  gearman    4u  IPv4 329744      0t0  TCP localhost:39072->localhost:4730 (ESTABLISHED)
php       29619  gearman    4u  IPv4 327233      0t0  TCP localhost:51570->localhost:4730 (ESTABLISHED)

It looks like with each time I stop and start supervisord, it creates another php process, and then another. It's only when I restart gearmand that it goes back to normal i.e. /etc/init.d/gearman-job-server stop && /etc/init.d/gearman-job-server start.

This seems abnormal to me being that when I stop supervisord, it's supposed to stop

Is this the way supervisord works?! Is there a way I can prevent this from happening?!

Thanks in advance.

EDIT

I found out what was causing the problem. It was a small conflict with the supervisord.conf and my init script.

My supervisord.conf file had the following settings:

pidfile=/tmp/supervisord.pid

But my init script at /etc/init.d/supervisord had the following setting:

NAME=supervisord
PIDFILE=/var/run/$NAME.pid

So I just changed the setting in supervisord.conf to match what was in my init script.

Also, I added stopsignal=KILL to the program config in my supervisord config file (supervisord.conf).

Thanks to Minaz for the direction.

Was it helpful?

Solution

I always include the stopsignal config option for my supervisor config files. This allows the gearman process to be killed when a stop is requested. Try this:

[program:gearman] 
command=/usr/bin/php php_gearman_worker.php
numprocs=1 
directory=/root/sandbox
stdout_logfile=/root/sandbox/supervisord.log 
environment=GEARMAN_USER=gearman 
autostart=true
autorestart=true
user=gearman
stopsignal=KILL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top