2014-11-05 40 views
1

我的芹菜服务器有一个正在运行的主管工作。现在我需要向它添加一个新任务,但不幸的是我的celery server命令未配置为自动跟踪这些动态更改。芹菜主管:如何重新启动主管工作,使新的芹菜任务工作?

这里是我的芹菜命令:

python manage.py celery worker --broker=amqp://username:[email protected]/our_app_vhost 

重新启动我的芹菜过程中,我都试过了,

sudo supervisorctl -c /etc/supervisor/supervisord.conf restart <process_name> 
supervisorctl stop all 
supervisorctl start all 
service supervisor restart 

但没有找到工作。如何重新启动它?

回答

4

如果要使用supervisorctl管理进程,则应在配置文件中配置supervisorctl,rpcinterface。

下面是一个示例配置文件。

sample.conf

[supervisord] 
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) 
logfile_maxbytes=50MB  ; (max main logfile bytes b4 rotation;default 50MB) 
logfile_backups=10   ; (num of main logfile rotation backups;default 10) 
loglevel=info    ; (log level;default info; others: debug,warn,trace) 
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) 
nodaemon=false    ; (start in foreground if true;default false) 
minfds=1024     ; (min. avail startup file descriptors;default 1024) 
minprocs=200     ; (min. avail process descriptors;default 200) 

[program:my_worker] 
command = python manage.py celery worker --broker=amqp://username:[email protected]/our_app_vhost 

[unix_http_server] 
file=/tmp/supervisor.sock ; (the path to the socket file) 

[supervisorctl] 
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket 

[rpcinterface:supervisor] 
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface 

现在用

supervisord -c sample.conf 

开始主管现在如果你想重新启动工人可以用

supervisorctl -c sample.conf restart my_worker 

做这将重新启动你的工人。另外,您也可以下降到主管外壳,你可以重新启动它

sudo supervisorctl -c sample.conf 
supervisor> restart my_worker 
my_worker: stopped 
my_worker: started 

注:

还有就是自动重工人芹菜选项

python manage.py celery worker --autoreload --broker=amqp://username:[email protected]/our_app_vhost 

这应该在开发中模式。不建议在生产中使用它。

更多关于celery docs

1

您可以在/etc/supervisor/conf.d/中写下您的芹菜任务。创建一个像celery.conf芹菜的新配置文件。

假设你的virtualenv是venv,Django项目是样品,你的芹菜脚本在_celery.py

这个文件看起来应该像

[program:celery] 
command=/home/ubuntu/.virtualenvs/venv/bin/celery --app=sample._celery:app worker --loglevel=INFO 
directory=/home/ubuntu/sample/ 
user=ubuntu 
numprocs=1 
stdout_logfile=/home/ubuntu/logs/celery-worker.log 
stderr_logfile=/home/ubuntu/logs/celery-error.log 
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 

写你需要运行

这监督员程序后,

如果添加管理程序运行这个 $ sudo supervisorctl reread

芹菜:可用

如果添加/更新监督员程序运行此 $ sudo supervisorctl update

芹菜:额外的处理组

要检查你的芹菜任务的状态 $ sudo supervisorctl status celery

芹菜正在进行PID 18020,运行时间〇时00分50秒

要停止芹菜任务 $ sudo supervisorctl stop celery

芹菜:停止

要启动芹菜任务 $ sudo supervisorctl start celery

芹菜:开始

要重新启动芹菜任务(这将停止并重新启动指定的任务) $ sudo supervisorctl restart celery

芹菜:停止 芹菜:开始