我有一个小应用程序,我想开始使用supervisord。我尝试了以下
我的初始shell脚本可以通过将PID保存在文本文件中来启动和停止celery和Flask作为守护进程。由于supervisord将负责杀死它,我摆脱了停止部分并且没有守护脚本。
经过反复试验后,我认为这些脚本和配置很有意义,但它们不起作用。
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
没有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相同
我收到一条消息,说找不到命令来源。我在同一目录中的终端上尝试了相同的命令,它可以工作。
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
Conf
[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"命令" ,即使我觉得在上述所有情况下都不需要。它在文档中提到了here。
我收到以下错误,但我无法找出原因: -
无法生成
流程退出太快
答案 0 :(得分:2)
在#2的情况下,你实际上并不需要激活virtualenv。您可以将其更改为:
[group:hitler]
programs=gunicorn,celery
[program:gunicorn]
command=/absolute/path/to/env/bin/gunicorn /absolute/path/to/gunicornserve:app -b 0.0.0.0:3333 -w 2
directory=/home/abhirath/Desktop/Hitler
[program:celery]
command=/absolute/path/to/env/bin/celery -A testrunner worker --concurrency=4 --loglevel=info
directory=/home/abhirath/Desktop/Hitler
答案 1 :(得分:0)
@MohammadAmin和@ymonad给出了我在这个答案中使用的精彩建议。由于这里给出的解释,我找到了一个更简单的解决方案 - > Supervising virtualenv django app via supervisor
脚本文件
[group:hitler]
programs=gunicorn,celery
[program:gunicorn]
command=bash -c "./hitler.sh gunicorn"
directory=/home/abhirath/Desktop/Hitler
environment=PATH="/home/abhirath/Desktop/Hitler"
stderr_logfile=/home/abhirath/Desktop/Hitler/Logs/gunicornerr.log
stderr_logfile_backups=1
stdout_logfile=/home/abhirath/Desktop/Hitler/Logs/gunicornout.log
stdout_logfile_backups=1
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
startretries=0
[program:celery]
command=bash -c "./hitler.sh celery"
directory=/home/abhirath/Desktop/Hitler
environment=PATH="/home/abhirath/Desktop/Hitler"
stderr_logfile=/home/abhirath/Desktop/Hitler/Logs/celeryerr.log
stderr_logfile_backups=1
stdout_logfile=/home/abhirath/Desktop/Hitler/Logs/celeryout.log
stdout_logfile_backups=1
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
startretries=0
由于我将项目目录指定为环境路径,因此我无需在环境中指定Python解释器的绝对路径。
Supervisord Conf
git rebase master