[Django]-Using Django-Q in production

7👍

Systemd is a good way to manage it. You can also put the logs in a folder attached to the site. I put all my config files in the same folder as the django app, so I can keep them on the same version control. In practice it looks something like this:

/web/example/config/example-qcluster.service:

[Unit]
Description=example qcluster daemon
After=network.target

[Service]
User=<web user>
Group=www-data
RuntimeDirectory=example
RuntimeDirectoryMode=0755
PIDFile=/run/example/qcluster.pid
WorkingDirectory=/web/example
EnvironmentFile=/web/example/.env
ExecStart=/web/example/env/bin/python manage.py qcluster
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
StandardOutput=file:/web/example/logs/qcluster.std.log
StandardError=file:/web/example/logs/qcluster.err.log

[Install]
WantedBy=multi-user.target

Then of course link, enable and start it:

sudo ln -s /web/example/config/example-qcluster.service /etc/systemd/system/example-qcluster.service
sudo systemctl enable example-qcluster.service
sudo systemctl start example-qcluster.service

Then, you can check it’s working by tailing the log:

tail -f /web/example/logs/qcluster.std.log

Leave a comment