I have set up gunicorn to server two Django sites, as per this setup. This works well. If I run:
# systemctl start gunicorn@my_website.service
Then all is well and my website is being served as expected. So I move to enable this on boot:
# systemctl enable gunicorn@my_website.service
Let's check it's enabled:
# systemctl is-enabled gunicorn@my_website.service
enabled
Looks good. Now, let's reboot...
Turns out my site is not up. nginx is working, it just seems that gunicorn isn't doing it's thing. Let's investigate:
# systemctl status gunicorn@my_website.service
● gunicorn@my_website.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/[email protected]; indirect; vendor preset: enabled)
Active: inactive (dead)
Hmmm... that looks weird. Checking out the log since boot:
# journalctl -u gunicorn@my_website.service -b
-- Logs begin at Mon 2019-04-08 06:04:03 UTC, end at Thu 2020-10-15 13:23:30 UTC. --
-- No entries --
Very puzzling... not even a log entry! When I start the service manually we're back in operations:
# systemctl start gunicorn@my_website.service
# systemctl status gunicorn@my_website.service
● gunicorn@my_website.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/[email protected]; indirect; vendor preset: enabled)
Active: active (running) since Thu 2020-10-15 13:25:29 UTC; 30s ago
Main PID: 1272 (gunicorn)
Tasks: 4 (limit: 1151)
CGroup: /system.slice/system-gunicorn.slice/gunicorn@my_website.service
├─1272 /usr/bin/python3 /usr/local/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/my_website/gunicorn.sock my_website.wsgi:application
├─1294 /usr/bin/python3 /usr/local/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/my_website/gunicorn.sock my_website.wsgi:application
├─1297 /usr/bin/python3 /usr/local/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/my_website/gunicorn.sock my_website.wsgi:application
└─1298 /usr/bin/python3 /usr/local/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/my_website/gunicorn.sock my_website.wsgi:application
Oct 15 13:25:29 web systemd[1]: Started gunicorn daemon.
Oct 15 13:25:29 web gunicorn[1272]: [2020-10-15 13:25:29 +0000] [1272] [INFO] Starting gunicorn 19.9.0
Oct 15 13:25:29 web gunicorn[1272]: [2020-10-15 13:25:29 +0000] [1272] [INFO] Listening at: unix:/home/my_website/gunicorn.sock (1272)
Oct 15 13:25:29 web gunicorn[1272]: [2020-10-15 13:25:29 +0000] [1272] [INFO] Using worker: sync
Oct 15 13:25:29 web gunicorn[1272]: [2020-10-15 13:25:29 +0000] [1294] [INFO] Booting worker with pid: 1294
Oct 15 13:25:29 web gunicorn[1272]: [2020-10-15 13:25:29 +0000] [1297] [INFO] Booting worker with pid: 1297
Oct 15 13:25:29 web gunicorn[1272]: [2020-10-15 13:25:29 +0000] [1298] [INFO] Booting worker with pid: 1298
And indeed, my website works now! But why is this seemingly not even run on boot when it's enabled? How to debug this?
Running Ubuntu 18.04.
As requested, the content of the [email protected]
file below:
# cat /etc/systemd/system/[email protected]
[Unit]
Description=gunicorn daemon
After=network.target
PartOf=gunicorn.target
# Since systemd 235 reloading target can pass through
ReloadPropagatedFrom=gunicorn.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/%i/
ExecStart=/usr/local/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/home/%i/gunicorn.sock \
%i.wsgi:application
[Install]
WantedBy=gunicorn.target