gpt4 book ai didi

python - 无法使用 Supervisord 启动 Python 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:09:01 24 4
gpt4 key购买 nike

我有一个小应用程序,我想开始使用 supervisord。我试过以下方法

我的初始 shell 脚本可以通过将 PID 保存在文本文件中来启动和停止 celery 和 Flask 作为守护进程。由于 supervisord 会负责终止它,所以我去掉了停止部分并且不守护脚本。

经过反复试验,我认为这些脚本和 conf 组合是合理的,但它们不起作用。

1

外壳脚本

#!/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 相同

我收到一条消息说找不到命令。我在同一目录中的终端上尝试了相同的命令,它有效。


3

外壳脚本

#!/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

session

[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在文档中。

我收到以下错误,但我无法弄清楚原因:-

Could not spawn

Process Exited too quickly

最佳答案

在#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

关于python - 无法使用 Supervisord 启动 Python 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40882464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com