python

04
Apr

Running gunicorn from a Python virtual environment with systemd and selinux

There are a lot of tutorials out there for running a gunicorn server on systemd, but I wasn't able to find one that actually told me how to do so in selinux. Since I'd never used selinux before, this relatively simple task turned into hours of trial and error, but my loss is your gain. YMMV dependent on how custom your selinux setup is, but this worked for me:

Assuming your project is in /www/myproject:

/www/myproject/gunicorn_config.py:

bind = 'unix:/run/gunicorn.sock'
worker_class = 'sync'
workers = 4
timeout = 60

/etc/systemd/system/gunicorn.socket:

[Unit]
Description=
Read more
1 min read