如何将我的 supervisord 配置从 python2 转换为 python3?

how do i convert my supervisord configuration from python2 to python3?

请检查下面的更新

i am yet to see any working supervisor 3 sample configuration, thus no helpful doc out there on supervisor 3 and so here i am looking for help

我有以下 supervisord 配置

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
user=root            ;

; 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:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:uvicorn]
command = uvicorn --host 0.0.0.0 --port 5000 app.app:app
autostart=true
autorestart=true
priority=5
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:celery-worker]
command=celery -A app.app:celery worker -l info
autostart=true
autorestart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:celery-beat]
command=celery -A app.app:celery beat -l info
autostart=true
autorestart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

然后我使用以下命令启动 supervisord

/usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf

这是我在 运行 过程中看到的

# ps aux

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1   5488  3072 ?        Ss   05:41   0:00 /bin/bash entrypoint.test.sh
root         6  0.0  1.0  26996 20960 ?        S    05:41   0:01 /usr/bin/python2 /usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf
root         9  0.7  1.7 115232 34672 ?        Sl   05:41   0:11 /usr/local/bin/python /usr/local/bin/uvicorn --host 0.0.0.0 --port 5000 app.app:app
root        10  0.4  2.3  56344 48520 ?        S    05:41   0:07 /usr/local/bin/python /usr/local/bin/celery -A app.app:celery worker -l info
root        11  0.0  2.2  54684 46380 ?        S    05:41   0:01 /usr/local/bin/python /usr/local/bin/celery -A app.app:celery beat -l info
root        15  0.0  1.8  53724 37328 ?        S    05:41   0:00 /usr/local/bin/python /usr/local/bin/celery -A app.app:celery worker -l info
root        16  0.0  1.8  53728 37180 ?        S    05:41   0:00 /usr/local/bin/python /usr/local/bin/celery -A app.app:celery worker -l info
root        28  0.1  0.1   5752  3600 pts/0    Ss   06:06   0:00 bash
root        34  0.0  0.1   9392  3048 pts/0    R+   06:06   0:00 ps aux

如您所见,这是 运行 supervisor 2 和 python2 但是我要对 supervisord 配置文件进行哪些更改才能将 supervisor 3 与 python3 一起使用?

谢谢

UPDATE:

supervisor 安装在 docker 映像中 apt-get install supervisor

我需要 pip install supervisor 吗? 不确定这是否是这里的问题

# pip -V
pip 20.2.4 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

# python -V
Python 3.8.3

# pip freeze
amqp==5.0.2
billiard==3.6.3.0
celery==5.0.2
click==7.1.2
click-didyoumean==0.0.3
click-repl==0.1.6
fastapi==0.61.2
h11==0.11.0
kombu==5.0.2
prompt-toolkit==3.0.8
pydantic==1.7.2
pytz==2020.4
redis==3.5.3
six==1.15.0
starlette==0.13.6
uvicorn==0.12.2
vine==5.0.0
wcwidth==0.2.5

对主管 2 到 3 有帮助 link http://supervisord.org/upgrading.html

最后也安装 pip install supervisor 并且仍然得到相同的 supervisord 2

# pip freeze
amqp==5.0.2
billiard==3.6.3.0
celery==5.0.2
click==7.1.2
click-didyoumean==0.0.3
click-repl==0.1.6
fastapi==0.61.2
h11==0.11.0
kombu==5.0.2
prompt-toolkit==3.0.8
pydantic==1.7.2
pytz==2020.4
redis==3.5.3
six==1.15.0
starlette==0.13.6
supervisor==4.2.1
uvicorn==0.12.2
vine==5.0.0
wcwidth==0.2.5

Issue is with the apt-get package for Debian 10 which is base OS for the python 3 base docker image am using comes with supervisor 3.3.5 rather than latest supervisor 4.2.1 So seems that is what issue is here

File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 787, in resolve raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'supervisor==3.3.5' distribution was not found and is required by the application

来自主管 github repo

Supervisor is intended to work on Python 3 version 3.4 or later and on Python 2 version 2.7.

所以 supervisor 3.4 以下的任何东西都将使用 python 2

所以需要找到一种方法从源代码安装 supervisor OS 包

Issue is with the apt-get package for Debian 10 which is base OS for the python 3 base docker image am using comes with supervisor 3.3.5 rather than latest supervisor 4.2.1 So seems that is what issue is here

# cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

# apt-cache show supervisor
Package: supervisor
Version: 3.3.5-1
Installed-Size: 1447
Maintainer: Python Applications Packaging Team <python-apps-team@lists.alioth.debian.org>
Architecture: all
Depends: lsb-base, python-pkg-resources, python-meld3, python:any (<< 2.8), python:any (>= 2.7~)
Suggests: supervisor-doc
Description: System for controlling process state
Description-md5: 965223e7558e3d49e112406ca88bda2b
Homepage: http://supervisord.org/
Tag: implemented-in::python, role::program
Section: admin
Priority: optional
Filename: pool/main/s/supervisor/supervisor_3.3.5-1_all.deb
Size: 284260
MD5sum: 4a40c0ed0774b8b43c5645967129eeb1
SHA256: 9f68f3559eac10840d54301d56cca6ba8f7e202398b2f24bbf8e71a2a59785cb

这是我得到的错误

File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 787, in resolve raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'supervisor==3.3.5' distribution was not found and is required by the application

来自主管 github 回购 https://github.com/Supervisor/supervisor#supported-platforms

Supervisor is intended to work on Python 3 version 3.4 or later and on Python 2 version 2.7.

所以 supervisor 3.4 以下的任何东西都将使用 python 2

所以需要找到一种方法从源代码安装 supervisor OS 包

修复: 我更新了基础 python docker 图像以使用 supervisor 4.2.0

附带的 python:alpine
/ # apk add supervisor
(1/9) Installing python3 (3.8.5-r0)
(2/9) Installing py3-meld3 (2.0.1-r0)
(3/9) Installing py3-ordered-set (4.0.1-r0)
(4/9) Installing py3-appdirs (1.4.4-r1)
(5/9) Installing py3-parsing (2.4.7-r0)
(6/9) Installing py3-six (1.15.0-r0)
(7/9) Installing py3-packaging (20.4-r0)
(8/9) Installing py3-setuptools (47.0.0-r0)
(9/9) Installing supervisor (4.2.0-r0)
Executing busybox-1.31.1-r16.trigger
OK: 63 MiB in 44 packages

我们开始吧

# ps aux
PID   USER     TIME  COMMAND
    1 root      0:00 /bin/sh entrypoint.alpine.sh
    6 root      0:00 {supervisord} /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervisord.conf
    8 root      0:01 {uvicorn} /usr/local/bin/python /usr/local/bin/uvicorn --host 0.0.0.0 --port 5000 app.app:app
    9 root      0:00 {celery} /usr/local/bin/python /usr/local/bin/celery -A app.app:celery beat -l info
   10 root      0:01 {celery} /usr/local/bin/python /usr/local/bin/celery -A app.app:celery worker -l info
   12 root      0:00 {celery} /usr/local/bin/python /usr/local/bin/celery -A app.app:celery worker -l info
   13 root      0:00 {celery} /usr/local/bin/python /usr/local/bin/celery -A app.app:celery worker -l info
   21 root      0:00 sh
   27 root      0:00 ps aux

完成!!!