跑主管
-
建立一個指令碼來啟動芹菜工人。在你的應用中插入指令碼。例如:
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