0

I'm following this tutorial to deploy my Django app, but modified my executable /var/www/my_django_project/bin/gunicorn_start to use my conda env instead of virtualenv.

CONDA_SRC=/home/justin/anaconda3/etc/profile.d/conda.sh
GUNICORN=/home/justin/anaconda3/pkgs/gunicorn-20.0.4-py38_0/bin/gunicorn
...
source $CONDA_SRC
conda activate myenv

When executing sudo bin/gunicorn_start, I got:

“starting backend”
bin/gunicorn_start: /home/justin/anaconda3/pkgs/gunicorn-20.0.4-py38_0/bin/gunicorn: /opt/anaconda1anaconda2anaconda3/bin/python: bad interpreter: No such file or directory
bin/gunicorn_start: line 25: /home/justin/anaconda3/pkgs/gunicorn-20.0.4-py38_0/bin/gunicorn: Success

and my supervisor.log shows:

supervisor: couldn't exec /var/www/my_django_project/bin/gunicorn_start: EACCES
supervisor: child process was not spawned
Soubriquet
  • 101
  • 2

1 Answers1

0

I fixed this by changing the base of my GUNICORN path to the directory containing my conda environment binaries. This can be found with which python while your conda env is activated, which gives: /home/justin/anaconda3/envs/production/bin/python. Use /home/justin/anaconda3/envs/production/bin/gunicorn.

bin/gunicorn_start executable:

#!/bin/bash

NAME=”backend”
DJANGODIR=/var/www/my_django_project/backend
SOCKFILE=/var/www/my_django_project/run/gunicorn.sock
USER=django
GROUP=my_django_project
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=backend.settings
DJANGO_WSGI_MODULE=backend.wsgi
CONDA_SRC=/home/justin/anaconda3/etc/profile.d/conda.sh
GUNICORN=/home/justin/anaconda3/envs/production/bin/gunicorn

echo “starting backend”

cd $DJANGODIR
    source $CONDA_SRC
conda activate myenv
    export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
    export PYTHONPATH=$DJANGODIR:$PYTHONPATH
    
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

exec $GUNICORN
 ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-

My supervisor config was also missing sh in the command argument and my supervisor config used the wrong extension. Make sure the extension is .conf. Heres' my updated django.conf:

[program:django]
command =sh /var/www/my_django_project/bin/gunicorn_start
user = django
stdout_logfile = /var/www/my_django_project/backend/logs/supervisor.log
redirect_stderr = true
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8

Hope this helps anyone else having this issue.

Soubriquet
  • 101
  • 2