跑主管
-
创建一个脚本来启动芹菜工人。在你的应用中插入脚本。例如:
stack/bin/celery_worker_start
#!/bin/bash NAME="StackOverflow Project - celery_worker_start" PROJECT_DIR=/home/stackoverflow/apps/proj/proj/ ENV_DIR=/home/stackoverflow/apps/proj/env/ echo "Starting $NAME as `whoami`" # Activate the virtual environment cd "${PROJECT_DIR}" if [ -d "${ENV_DIR}" ] then . "${ENV_DIR}bin/activate" fi celery -A stack --loglevel='INFO'
-
为新创建的脚本添加执行权限:
chmod u+x bin/celery_worker_start
-
安装主管(如果已安装主管,请跳过此测试)
apt-get install supervisor
-
为你的主管添加配置文件,以启动你的芹菜。把它放在
/etc/supervisor/conf.d/stack_supervisor.conf
[program:stack-celery-worker] command = /home/stackoverflow/apps/stack/src/bin/celery_worker_start user = polsha stdout_logfile = /home/stackoverflow/apps/stack/src/logs/celery_worker.log redirect_stderr = true environment = LANG = en_US.UTF-8,LC_ALL = en_US.UTF-8 numprocs = 1 autostart = true autorestart = true startsecs = 10 stopwaitsecs = 600 priority = 998
-
重读并更新主管
sudo supervisorctl reread stack-celery-worker: available sudo supervisorctl update stack-celery-worker: added process group
-
基本命令
sudo supervisorctl status stack-celery-worker stack-celery-worker RUNNING pid 18020, uptime 0:00:50 sudo supervisorctl stop stack-celery-worker stack-celery-worker: stopped sudo supervisorctl start stack-celery-worker stack-celery-worker: started sudo supervisorctl restart stack-celery-worker stack-celery-worker: stopped stack-celery-worker: started