gpt4 book ai didi

python-3.x - 无法在 Python 3.8 上运行 Supervisor

转载 作者:行者123 更新时间:2023-12-05 07:05:32 27 4
gpt4 key购买 nike

我的 Django 项目是在 python 3.8 中。我添加了 celery 来处理异步功能。在生产中,我打算使用 supervisor。在尝试运行主管时出现以下错误

pkg_resources.DistributionNotFound: The 'supervisor==3.3.1' distribution was not found and is required by the application

我尝试使用 pip 安装 3.3.1,但 python 3.8 不支持它。

我尝试使用 http://supervisord.org/但是关于如何设置它在服务器启动时自动运行的文档含糊不清。如何在后台启动、停止和重新启动。

最佳答案

我能够使用 Python 3.8 对其进行设置。不要使用ubuntu提供的supervisor

我正在为我的项目使用 virtualenv,我在 requirement.txt 中添加

supervisor==4.2.0

检查目录/var/log/supervisord 是否存在。如果没有,则创建此目录。它将用于主管 sock 文件和日志

检查/etc/supervisor/supervisord.conf 文件是否存在。如果没有,则创建包含以下内容的文件

[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket

; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf

完成后,在/etc/supervisor/conf.d 中创建文件例如我有 celery-worker.conf

[program:celeryworkerdemo]
command=/home/ubuntu/venv/bin/celery -A celeryworkerdemo worker -l debug
directory=/home/ubuntu/celeryworkerdemo/
user=ubuntu
numprocs=1
stdout_logfile=/home/ubuntu/logs/celerylogs/celeryworkerdemo_worker.log
stderr_logfile=/home/ubuntu/logs/celerylogs/celeryworkerdemo_worker_err.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998

完成后,执行以下命令

sudo systemctl daemon-reload
sudo systemctl enable supervisord && sudo systemctl start supervisors

运行以下命令查看状态

sudo systemctl status supervisord

关于python-3.x - 无法在 Python 3.8 上运行 Supervisor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62700787/

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