[Fixed]-Django Gunicorn error

1πŸ‘

βœ…

The nginx looks good but for the .sock file I would recommend to change it and call a .sh file:
myproject.sock:

[Unit]
Description=Myproject gunicorn daemon

[Service]
Type=simple
User=root
ExecStart=/home/root/myproject_start.sh

[Install]
WantedBy=multi-user.target

myproject_start.sh

#!/bin/bash

NAME="myproject"                              
DJANGODIR=/home/root/myproject           
SOCKFILE=/home/root/myproject/myproject.sock      
USER=root                                       
#GROUP=www-data                                   
NUM_WORKERS=3                                    
DJANGO_SETTINGS_MODULE=myproject.settings   
DJANGO_WSGI_MODULE=myproject.wsgi

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
#IF YOU HAVE VIRTUALENV - OTHERWISE CHOOSE YOUR PYTHON DIR
source /home/root/myproject/myprojectenv/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

exec /home/root/myproject/myprojectenv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
    --name $NAME \
    --workers $NUM_WORKERS \
    --user $USER \
    --bind=unix:$SOCKFILE
πŸ‘€nrhode

Leave a comment