【Python】supervisor安装和管理celery

时间:2022-09-07 07:22:42

参考:http://blog.csdn.net/wawa8899/article/details/52743861

参考:http://www.cnblogs.com/mountaingeek/p/5911291.html

参考:http://www.linuxyw.com/718.html

参考:http://www.iitshare.com/supervisord-manage-process.html

参考:http://*.com/questions/20346851/running-celery-as-root

运行生成配置文件:

[root@host /]# echo_supervisord_conf > /etc/supervisord.conf
...
pkg_resources.DistributionNotFound: meld3>=0.6.
找到supervisor-3.3.-py2..egg-info/requires.txt,把文件里面meld3 >= 0.6.5注释掉,然后再执行

配置

[program:dopcelerybeat]
command=python manage.py celery beat
numprocs=
directory=/path/
autostart=true
startsecs=
startretries=
stopwaitsecs=
killasgroup=true
user=root
redirect_stderr=true
stdout_logfile=/path/logs/supervisord-celery-beat.log
stderr_logfile=/path/logs/supervisord-celery-beat-error.log [program:dopceleryworker]
command=python manage.py celery worker -l info
numprocs=
directory=/path/
autostart=true
startsecs=
startretries=
stopwaitsecs=
killasgroup=true
user=root
redirect_stderr=true
stdout_logfile=/path/logs/supervisord-celery-worker.log
stderr_logfile=/path/logs/supervisord-celery-worker-error.log [group:dopcelery]
programs=dopcelerybeat,dopceleryworker
; priority= ; the relative start priority (default )

运行celery时报错的解决方法:

1st solution - Manually type command at terminal
$ export C_FORCE_ROOT='true' 2nd solution - Edit shell configuration
$ vi ~/.bashrc # add following line
export C_FORCE_ROOT='true' $ source ~/.bashrc 3rd solution - Edit manage.py of Django
import os if __name__ == '__main__':
os.environ.setdefault('C_FORCE_ROOT', 'true')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{PATH TO SETTINGS FILE}') execute_from_command_line(sys.argv)

命令supervisorctl可以使用start/stop/status管理每个进程

[root@d11092353 supervisor-3.3.-py2..egg-info]# supervisorctl
dopcelery:dopcelerybeat STOPPED Dec : PM
dopcelery:dopceleryworker RUNNING pid , uptime ::
supervisor> status dopcelery:dopcelerybeat
dopcelery:dopcelerybeat STOPPED Dec : PM
supervisor>

supervisorctl API:官方文档 http://www.supervisord.org/api.html

import xmlrpclib
server = xmlrpclib.Server('http://127.0.0.1:9900/RPC2')
server.supervisor.getState()
返回 >>> {'statename': 'RUNNING', 'statecode': 1}
server.supervisor.getProcessInfo('group:name')
返回 >>> 任务状态