Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping Supervisor doesn't stop Celery workers

How do I ensure sub-processes are stopped when I stop Supervisord?

I'm using Supervisord to run two Celery workers. The command for each worker is:

command=/usr/local/myapp/src/manage.py celery worker --concurrency=1 --loglevel=INFO

When I start supervisord, they run perfectly, but when I run sudo service supervisord stop, it reports my workers stop:

celery_1: stopped
celery_2: stopped

However, when I run ps aux | grep celery I see they're still running:

www-data 27667  0.0  1.5 318420 64360 ?        S    10:45   0:00 manage.py celery worker --concurrency=1 --loglevel=INFO
www-data 27668  0.0  1.5 318420 318416 ?        S    10:45   0:00 manage.py celery worker --concurrency=1 --loglevel=INFO
like image 576
Cerin Avatar asked Jun 12 '13 15:06

Cerin


People also ask

How do you stop a celery worker?

In this setup, when running a celery worker with --pool solo option, kill -KILL <pid> stops worker immediately.

How do you kill a Supervisord process?

Finally, you can exit supervisorctl with Ctrl+C or by entering quit into the prompt: supervisor> quit.

What is supervisor in celery?

Supervisor is a Python program that allows you to control and keep running any unix processes. It can also restart crashed processes. We use it to make sure Celery workers are always running. First, Install supervisor sudo apt-get install supervisor.


2 Answers

i believe stopping the supervisor service stops the supervisor daemon, not the supervisor process that is managing your celeryworkers

supervisorctl stop all should allow you stop the workers, and also allow you to start/restart them

http://supervisord.org/running.html#running-supervisorctl

like image 134
dm03514 Avatar answered Nov 10 '22 01:11

dm03514


The reason I ended up here is that when I was using supervisor to start and stop my celery processes, the celery workers were not stopping, which lead to an accumulation of workers.

I tried various settings in supervisor, such as stopsignal, and killasgroup. None of them stopped the workers.

At this point, it appears that the celery process does not send signals to the workers when it is stopped.

What I ended up doing was to add:

ps auxww | grep 'celery worker' | awk '{print $2}' | xargs kill -9

to my scripts. This is from the celery docs

At the end of this command, I tried kill -TERM instead of kill -9, hoping that would kill the processes more gracefully. But that always left one process.

like image 33
Chuck Avatar answered Nov 10 '22 01:11

Chuck