Search code examples
pythongunicornsupervisordpipenv

set up pipenv with supervisor


I want to deploy dev server but I have a problem with starting celery and gunicorn. I'm using scripts for my purposes

celery.sh

#!/bin/bash 
cd /home/dev/app
pipenv run celery -A config worker -B -l info

and start.sh for gunicorn

#!/bin/bash
cd /home/dev/app
pipenv run gunicorn config.wsgi:application -b 127.0.0.1:8005 -w 2 -t 60 \

    --env DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE \

    --env DSN=$SENTRY_DSN \

    --env DATABASE_URL=$DATABASE_URL \

    --log-file - \

    --error-logfile /home/dev/app/errors.log 

Also here is my config for supervisor

[program:back]
directory=/home/dev/app/
command=/home/dev/bin/start
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true


[program:celery]
directory=/home/dev/app/
command=/home/dev/bin/celery
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true

When I'm running sudo supervisorctl start celery I'm getting the following error: /home/dev/bin/celery: line 3: pipenv: command not found

Also I added the following lines as pipenv documentation says (https://pipenv.readthedocs.io/en/latest/diagnose/)

[supervisord]
environment=LC_ALL='en_US.UTF-8',LANG='en_US.UTF-8'

UPDATE

Changed my supervisor config:

[program:back]
directory=/home/dev/app/
command=pipenv run gunicorn config.wsgi:application --bind 127.0.0.1:8005
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true


[program:celery]
directory=/home/dev/app/
command=pipenv run celery -A config:celery_app worker -B -l info
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true

And now I'm getting an error:

back: ERROR (no such file)

Solution

  • You need to give explicit path of gunicorn. Though I'm not sure about pipenv, but the error you are getting is because supervisor tries to find gunicorn in the directory. You should change your config file into something like this:

    [program:back]
    directory=/home/dev/app/
    command=/path/to/pipenv run /path/to/gunicorn config.wsgi:application --bind 127.0.0.1:8005
    

    Then you must restart your supervisord in order to load the settings.

    sudo service supervisord reload