Not able to run Supervisor on Python 3.8

Viewed 1605

My Django project is in python 3.8. I have added celery to process async function. On production, I am planning to use supervisor. While trying to run the supervisor I am getting the following error

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

I tried by installing 3.3.1 using pip but it is not supported by the python 3.8.

I tried using http://supervisord.org/ but documentation is vague on how to setup it autorun on server start. How to start it in background, stop and restart.

2 Answers

I was able to set it up with Python 3.8. Do not use supervisor provided by ubuntu

I am using virtualenv for my project and I add in requirement.txt

supervisor==4.2.0

Check if directory /var/log/supervisord exist or not. If not, then create this directory. It will be used for supervisor sock file and logs

check if /etc/supervisor/supervisord.conf file exist or not. If not, then create file with below content

[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

Once done, create files inside /etc/supervisor/conf.d e.g. I have 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

Once this is done, run following commands

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

Run following command to see status

sudo systemctl status supervisord

Im running supervisor in 3.8 by following this steps

  1. install using pip/pip3
pip3 install supervisor
  1. modify the supervisor service. change the path /usr/local/supervisord to /usr/local/bin/supervisord
vim /lib/systemd/system/supervisor.service
  1. reload the daemon
sudo systemctl daemon-reload
  1. start the service.
sudo systemctl start supervisor.service
Related