Skip to content

Instantly share code, notes, and snippets.

@aldnav
Forked from afk-mario/[email protected]
Created July 22, 2017 16:45
Show Gist options
  • Save aldnav/a97592baaba938581a39909cd6cca643 to your computer and use it in GitHub Desktop.
Save aldnav/a97592baaba938581a39909cd6cca643 to your computer and use it in GitHub Desktop.
Django + Gunicorn + VirtualEnv + Systemd
[Unit]
Description=Gunicorn for project %I
After=network.target
After=syslog.target
[Service]
EnvironmentFile=/etc/conf.d/django_%i
ExecStart=/usr/bin/start_gunicorn
Restart=always
SyslogIdentifier=gunicorn%I
[Install]
WantedBy=multi-user.target
PORT=8000
SRC_PATH="<PATH_TO_DJANGO_APP>"
ENV_PATH="<PATH_TO_VIRTUAL_ENVIROMENT>"
APP_NAME="<NAME_OF_THE_APP"
# Make sure /var/log/gunicorn exists!
ACCESS_LOGFILE="/var/log/gunicorn/NAME_OF_THE_APP_access.log"
ERROR_LOGFILE="/var/log/gunicorn/NAME_OF_THE_APP_error.log"
#!/bin/bash
exec "${ENV_PATH}/bin/gunicorn" \
--bind="127.0.0.1:${PORT}" \
--access-logformat="%({X-Real-IP}i)s %(l)s %(u)s %(t)s \'%(r)s\' %(s)s %(b)s \'%(f)s\' \'%(a)s\'" \
--access-logfile="$ACCESS_LOGFILE" \
--error-logfile="$ERROR_LOGFILE" \
--log-level="warning" \
--chdir="$SRC_PATH" \
"${APP_NAME}.wsgi:application"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment