芹菜不会重新启动子进程

Celery doesn't restart subprocesses

我在部署 celery 时遇到问题 - 当我重新启动它时,旧的子进程不会停止并继续处理一些作业。我使用 supervisord 来 运行 芹菜。这是我的配置:

$ cat /etc/supervisor/conf.d/celery.conf 
[program:celery]
; Full path to use virtualenv, honcho to load .env
command=/home/ubuntu/venv/bin/honcho run celery -A stargeo worker -l info --no-color

directory=/home/ubuntu/app
environment=PATH="/home/ubuntu/venv/bin:%(ENV_PATH)s"
user=ubuntu
numprocs=1
stdout_logfile=/home/ubuntu/logs/celery.log
stderr_logfile=/home/ubuntu/logs/celery.err
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998

这是芹菜过程的样子:

$ ps axwu | grep celery
ubuntu     983  0.0  0.1  47692 10064 ?        S    11:47   0:00 /home/ubuntu/venv/bin/python /home/ubuntu/venv/bin/honcho run celery -A stargeo worker -l info --no-color
ubuntu     984  0.0  0.0   4440   652 ?        S    11:47   0:00 /bin/sh -c celery -A stargeo worker -l info --no-color
ubuntu     985  0.0  0.5 168720 41356 ?        S    11:47   0:01 /home/ubuntu/venv/bin/python /home/ubuntu/venv/bin/celery -A stargeo worker -l info --no-color
ubuntu     990  0.0  0.4 167936 36648 ?        S    11:47   0:00 /home/ubuntu/venv/bin/python /home/ubuntu/venv/bin/celery -A stargeo worker -l info --no-color
ubuntu     991  0.0  0.4 167936 36648 ?        S    11:47   0:00 /home/ubuntu/venv/bin/python /home/ubuntu/venv/bin/celery -A stargeo worker -l info --no-color

当我 运行 sudo supervisorctl restart celery 它只停止第一个进程 python ... honcho 一个,所有其他的继续。如果我试图杀死他们,他们会继续(kill -9 有效)。

这似乎是 a bug with honcho。我最终得到了从主管启动这个脚本的解决方法:

#!/bin/bash

source /home/ubuntu/venv/bin/activate
exec env $(cat .env | grep -v ^# | xargs) \
     celery -A stargeo worker -l info --no-color