6

Getting an error while trying to run a gunicorn script through supervisor. The gunicorn script is running fine while running it directly. I am on ubuntu 16.04 supervisor version : Getting

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

while running

sudo supervisorctl reread

my gunicron script to run Django application:

#!/bin/bash

NAME="applicant_screening"                                  # Name of the application
DJANGODIR=/home/applicant-screening-system/screening_backend             # Django project directory
#SOCKFILE=/home/track_ip/run/gunicorn.sock  # we will communicte using this unix socket
USER=root                                        # the user to run as
#GROUP=webapps                                     # the group to run as
NUM_WORKERS=3                                     # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=screening_backend.settings             # which settings file should Django use
DJANGO_WSGI_MODULE=screening_backend.wsgi                     # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source /home/screen-env/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER \
  --bind=0.0.0.0:8000 \
  --log-level=debug \
  --log-file=-
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Sidhartha
  • 988
  • 4
  • 19
  • 39

5 Answers5

12

This is the version mismatch between the requirement of supervisor and the python version installed. For this you need to:

  1. Install Python 2.7. (Since supervisor has a support for 2.* and the support for 3.* is still in development) https://askubuntu.com/a/981279

  2. Go to /usr/bin/supervisorctl file.

  3. Update the first line to

!/usr/bin/python2

to make the supervisor use the python 2.7 installed instead of python3.

Supervisorctl updated file

  1. Rerun the supervisorctl command.
Raj Srujan Jalem
  • 613
  • 5
  • 17
3

You will need to install supervisor via pip:

pip install supervisor==3.2.0
Stargazer
  • 1,442
  • 12
  • 19
0

There may be multiple different versions of supervisorctl installed. I encountered the same issue when I installed python3.5 and made python3 the default python version. I tried as followed and solved this issue.

  1. whereis supervisorctl will get the locations of all supervisor versions.
  2. Check the output location of the file supervisorctl. One of the ablove supervisorctl binary file can be correctly executed. Delete the other one and then the problem will be solved.
Wayne
  • 1
  • 1
0

Install supervisor using apt -

apt install supervisor -y

Generate the supervisor config file -

sudo su - && echo_supervisord_conf > /etc/supervisor/supervisord.conf

Add the gunicorn entry to the end of the config file -

[program: gunicorn]
command=/gunicorn_start.sh

Where gunicorn_start.sh is your gunicorn script.

Restart the supervisord service -

sudo service supervisor restart

Use supervisorctl using -

sudo supervisorctl
Kavish Baghel
  • 179
  • 1
  • 5
0

For my case, I have installed gunicorn3 instead of gunicorn and the problem was gone.

sudo apt install gunicorn3
Hafiz Muhammad Shafiq
  • 8,168
  • 12
  • 63
  • 121