skip to Main Content

I try setting up a django project with nginx and gunicorn but get a gunicorn error 203:
enter image description here

My installation is located at path /webapps/sarlex and all project files are owned by user "sarlex" and group "webapps".
The virtualenv is located at /webapps/sarlex/environment.
Gunicorn is located at /webapps/sarlex/environment/bin/ and owned by user sarlex.

Gunicorn configuration is set in /webapps/sarlex/gunicorn_start.sh:

NAME="sarlex"                                     # Name of the application
DJANGODIR=/webapps/sarlex/                        # Django project directory
SOCKFILE=/webapps/sarlex/run/gunicorn.sock        # we will communicte using this unix socket
USER=sarlex                                       # the user to run as
GROUP=webapps                                     # the group to run as
NUM_WORKERS=9                                     # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=sarlex.settings            # which settings file should Django use
DJANGO_WSGI_MODULE=sarlex.wsgi                    # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source /webapps/sarlex/environment/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 gunicorn ${DJANGO_WSGI_MODULE}:application 
  --name $NAME 
  --workers $NUM_WORKERS 
  --user=$USER --group=$GROUP 
  --bind=unix:$SOCKFILE 
  --log-level=debug 
--log-file=-

Executing gunicorn_start.sh works with environment activated and deactivated.

/etc/systemd/system/gunicorn.service is owned by root and has this content:

[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sarlex
Group=webapps
WorkingDirectory=/webapps/sarlex
ExecStart=/webapps/sarlex/gunicorn_start.sh
[Install]
WantedBy=multi-user.target

I tried to replace "User=Sarlex" with "User=root" but still get the same error.

The correct gunicorn it taken

enter image description here

Thanks for your help

2

Answers


  1. Chosen as BEST ANSWER

    Django failed starting because in one of my scripts I wrote "admin" in a path instead of "Admin". This didn't cause a problem on my windows PC where I am developing my code.


  2. What exactly is your question?

    • The export for DJANGO_SETTINGS_MODULE was awkward.
    • Enclose expressions and variable references in double quotes
    NAME="sarlex"                                     # Name of the application
    DJANGODIR=/webapps/sarlex/                        # Django project directory
    SOCKFILE=/webapps/sarlex/run/gunicorn.sock        # we will communicte using this unix socket
    USER=sarlex                                       # the user to run as
    GROUP=webapps                                     # the group to run as
    NUM_WORKERS=9                                     # how many worker processes should Gunicorn spawn
    DJANGO_SETTINGS_MODULE=sarlex.settings            # which settings file should Django use
    DJANGO_WSGI_MODULE=sarlex.wsgi                    # WSGI module name
    
    echo "Starting $NAME as `whoami`"
    
    # Activate the virtual environment
    source /webapps/sarlex/environment/bin/activate
    cd "$DJANGODIR"
    export 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 gunicorn "${DJANGO_WSGI_MODULE}:application" 
      --name "$NAME" 
      --workers "$NUM_WORKERS" 
      --user="$USER" --group="$GROUP" 
      --bind="unix:$SOCKFILE" 
      --log-level=debug 
    --log-file=-
    

    Please show /var/log/nginx/ error messages.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search