我的Django项目是python 3.8。我添加了芹菜来处理异步功能。在生产方面,我打算使用主管。尝试运行主管时,我收到以下错误
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 提供的主管
我正在为我的项目使用 virtualenv,我添加了要求.txt
supervisor==4.2.0
检查目录/var/log/supervisord 是否存在。如果没有,则创建此目录。它将用于主管袜子文件和日志
检查/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 中创建文件 例如,我有芹菜工人。
[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
按照以下步骤在 3.8 中运行主管
- 使用 pip/pip3 安装
pip3 install supervisor
- 修改主管服务。 将路径
/usr/local/supervisord
更改为/usr/local/bin/supervisord
vim /lib/systemd/system/supervisor.service
- 重新加载守护进程
sudo systemctl daemon-reload
- 启动服务。
sudo systemctl start supervisor.service