Django Deployment - issue with supervisor failing (exited too quickly)

September 7, 2018 633 views
Django Deployment Nginx Ubuntu 18.04

Hi everyone! I’m on my first Django deployment on Digital Ocean and I can’t seem to get past an error that’s rising when I check the status of supervisor.

here’s my happ.conf file (/etc/supervisor/conf.d.happ.conf)

[program:happ]
command=sh /home/happ/gunicorn_start
user=happ
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/happ/logs/gunicorn.log

and here’s my gunicornstart file (/home/happ/gunicornstart)

#!/bin/bash

NAME="happ"
DIR=/home/happ/happ
USER=happ
GROUP=happ
WORKERS=3
BIND=unix:/home/happ/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=happ.settings
DJANGO_WSGI_MODULE=happ.wsgi
LOG_LEVEL=error

cd $DIR
source ../venv/bin/activate

export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH

exec ../venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $WORKERS \
  --user=$USER \
  --group=$GROUP \
  --bind=$BIND \
  --log-level=$LOG_LEVEL \
  --log-file=-

Firstly I make the file executable:

chmod u+x gunicorn_start

Then I run the following commands:

sudo supervisorctl reread
sudo supervisorctl update

sudo supervisorctl status happ

And once I run the status command I get the following error:

Exited too quickly.

Here’s what the log file says:

/home/happ/gunicornstart: 2: /home/happ/gunicornstart:
: not found
/home/happ/gunicornstart: 12: /home/happ/gunicornstart:
: not found
/home/happ/gunicornstart: 13: cd: can’t cd to /home/happ/happ
/home/happ/gunicorn
start: 14: /home/happ/gunicornstart: source: not found
/home/happ/gunicorn
start: 15: /home/happ/gunicornstart:
: not found
/home/happ/gunicorn
start: 18: /home/happ/gunicornstart:
: not found
/home/happ/gunicorn
start: 19: exec: ../venv/bin/gunicorn: not found
Please note that the above commands are run inside the console not by the user root but by a user I created which is added to the sudoers list.

If anyone has any hint, please feel free to help out as I’ve been stuck on this issue for two days and I don’t really know where else to look for a solution. Thank you very much.

Be the first one to answer this question.