Skip to content

Instantly share code, notes, and snippets.

@samveen
Forked from afk-mario/django@.service
Created June 13, 2023 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samveen/047896af23a239c2b266093cc3f9a356 to your computer and use it in GitHub Desktop.
Save samveen/047896af23a239c2b266093cc3f9a356 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