【发布时间】:2017-04-14 10:16:14
【问题描述】:
我有一个小应用程序,我想开始使用 supervisord。我已经尝试了以下
- Installed supervisord and controlled a small script
- 阅读documentation 中的简介、运行 Supervisord 和配置文件部分
- Setting up groups in supervisord
我的初始 shell 脚本可以通过将 PID 保存在文本文件中来启动和停止 celery 和 Flask 作为守护进程。因为 supervisord 会负责杀死它,所以我去掉了 stop 部分并且不对脚本进行守护。
经过反复试验,这些是我认为有意义但不起作用的脚本和配置二重奏。
1
Shell 脚本
#!/bin/bash
if [[ $1 == "gunicorn" ]]
then
cd /home/abhirath/Desktop/Hitler
source env/bin/activate
python env/bin/gunicorn -b 0.0.0.0:3333 -w 3 gunicornserve:app
elif [[ $1 == "celery" ]]
then
cd /home/abhirath/Desktop/Hitler
source env/bin/activate
python env/bin/celery -A testrunner worker --concurrency=3 --loglevel=info
else
echo "Usage:-"
echo "To start celery:-"
echo "./hitler.sh celery"
echo "To start Gunicorn"
echo "./hitler.sh gunicorn"
fi
配置文件
[group:hitler]
programs=gunicorn,celery
[program:gunicorn]
command=/home/abhirath/Desktop/Hitler/hitler.sh gunicorn
stderr_logfile =/home/abhirath/Desktop/supervisor.err.log
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
[program:celery]
command=/home/abhirath/Desktop/Hitler/hitler.sh celery
stderr_logfile=/home/abhirath/Desktop/supervisor.err2.log
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
2
没有shell文件
[group:hitler]
programs=gunicorn,celery
[program:gunicorn]
command=source env/bin/activate; python env/bin/gunicorn -b 0.0.0.0:3333 -w 2 gunicornserve:app;
directory=/home/abhirath/Desktop/Hitler
[program:celery]
command=source env/bin/activate; python env/bin/celery -A testrunner worker --concurrency=4 --loglevel=info;
directory=/home/abhirath/Desktop/Hitler
stderr_logfile、autostart、autorestart、stopasgroup、killasgroup 同 #1
我收到一条消息说找不到命令 source。我在同一目录中的终端上尝试了相同的命令,它可以工作。
3
Shell 脚本
#!/bin/bash
if [[ $1 == "gunicorn" ]]
then
source env/bin/activate
python env/bin/gunicorn -b 0.0.0.0:3333 -w 3 gunicornserve:app
elif [[ $1 == "celery" ]]
then
source env/bin/activate
python env/bin/celery -A testrunner worker --concurrency=3 --loglevel=info
else
echo "Usage:-"
echo "To start celery:-"
echo "./hitler.sh celery"
echo "To start Gunicorn"
echo "./hitler.sh gunicorn"
fi
会议
[group:hitler]
programs=gunicorn,celery
[program:gunicorn]
command=./hitler.sh gunicorn
directory=/home/abhirath/Desktop/Hitler
[program:celery]
command=./hitler.sh celery
directory=/home/abhirath/Desktop/Hitler
stderr_logfile、autostart、autorestart、stopasgroup、killasgroup 同 #1
我也尝试过使用 command=bash -c "command here",尽管我觉得在上述所有情况下都不需要它。文档中提到了here。
我收到以下错误,但我无法弄清楚原因:-
无法生成
进程退出太快
【问题讨论】:
-
在#2中你不需要source。您可以使用:command=/path/to/env/bin/gunicorn -b 0.0.0.0:3333 -w 2 gunicornserve:app
-
注意#3。根据document“如果是相对的,将在supervisord的环境$PATH中搜索可执行文件”,表示
./hitler.sh是从$PATH搜索的,而不是/home/abhirath/Desktop/Hitler跨度> -
@ymonad 我不明白那部分。我会请我的同事详细说明这一点。谢谢:)
-
@MohammadAmin 但我需要激活 Python 环境。我不是吗?我会尽力回复你:)
-
@AbhirathMahipal 这意味着如果你想设置
command=./hitler.sh,你可能需要添加environment = PATH="/home/abhirath/Desktop/Hitler:/usr/local/bin:/usr/bin:/bin"
标签: python linux flask daemon supervisord