9 - Setting up Gunicorn - Deploying a Django Project - Ubuntu

You need to be subscribed to a plan to get access to the full course.

Gunicorn is one of the web servers we're going to use. Let's set it up!

Comments

Eric H | May 11, 23 01:21

Hey there. Great lesson! Just FYI - My script for launching gunicorn needed #!/bin/bash as the first line for the shell specification instead of #!/bin/sh in order to run properly.


Stein Ove Helset | May 20, 23 06:31

Ah, nice to know :-)

Eric H | May 11, 23 01:27

My paths are a bit wonky (my Django is a bit deeper in my directory structure) but here's an example template for those that need something to copy into their gunicorn_start. I've never used gunicorn and this lesson was a huge help!

#!/bin/bash

NAME='studynet'
DJANGODIR=/webapps/lms/vue-django-lms/studynet_django
SOCKFILE=/webapps/lms/lms_env/run/gunicorn.sock
USER=lmsuser
GROUP=webapps
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=studynet_django.settings
DJANGO_WSGI_MODULE=studynet_django.wsgi
TIMEOUT=120

cd $DJANGODIR
source ../../../lms_env/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

exec /webapps/lms/lms_env/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--timeout $TIMEOUT \
--user=$USER \
--group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-


Stein Ove Helset | May 20, 23 06:31

Yes, it can sometimes be a little bit different from server to server and similar. But once you've done it a couple of times, you will get the hang of it :-D

Giulio Nazzaro | Jan 11, 25 10:10

Part 9 video - Setting up gunicorn doesn't start ...

Add comment

Info

Please log in to comment!

Newsletter

Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.