-
-
Save aldnav/a97592baaba938581a39909cd6cca643 to your computer and use it in GitHub Desktop.
Django + Gunicorn + VirtualEnv + Systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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