Skip to content

Instantly share code, notes, and snippets.

@PraneethKarnena
Last active August 10, 2021 06:26
Show Gist options
  • Save PraneethKarnena/e41737f92c9d15023ef4e41f58f83758 to your computer and use it in GitHub Desktop.
Save PraneethKarnena/e41737f92c9d15023ef4e41f58f83758 to your computer and use it in GitHub Desktop.
Run Gunicorn as a service
# /etc/systemd/system/gunicorn.service
# sudo systemctl enable gunicorn
# sudo systemctl daemon-reload
# sudo service gunicorn restart
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
Type=notify
# the specific user that our service will run as
User=username
Group=username
# another option for an even more restricted service is
# DynamicUser=yes
# see http://0pointer.net/blog/dynamic-users-with-systemd.html
RuntimeDirectory=gunicorn
WorkingDirectory=/home/username/projects/project-root/
ExecStart=/home/username/projects/project-root/ENV/bin/gunicorn --bind=127.0.0.1:8000 --workers=2 --worker-class=gevent --threads=8 --worker-connections=100000 --timeout=63 --keep-alive=60 project.wsgi
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment