Ubuntu 18.04
I'm trying to make Gunicorn web server start on boot.
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
[Service]
# the specific user that our service will run as
User=pcask
Group=pcask
WorkingDirectory=/home/michael/PycharmProjects/pcask/pcask
ExecStart=gunicorn pcask.wsgi
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=true
[Install]
WantedBy=multi-user.targetPermissions
pcask@tmpgmv:~/pcask/venv/lib/python3.8/site-packages$ ls -la |grep gunicorn
drwxrwxr-x 7 pcask pcask 4096 Jul 28 19:32 gunicorn
drwxrwxr-x 2 pcask pcask 4096 Jul 28 19:32 gunicorn-20.0.4.dist-infoOn reboot the server is not running. Namely when I open my websie, it shows 502 Bad gateway. This means that Gunicorn is not running.
Could you tell me whether there is an error log where I can see what went wrong when this service file was used on boot. And whether it was used at all.
ADDED LATER
$ sudo journalctl -u gunicorn.service
[sudo] password for pcask:
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Fri 2020-08-14 12:36:57 MSK; 1min 11s ago Process: 439 ExecStart=/home/pcask/pcask/venv/lib/python3.8/site-packages/gunicorn pcask.wsgi:application (code=exited, status=203/EXEC) Main PID: 439 (code=exited, status=203/EXEC)
Aug 14 12:36:57 tmpgmv systemd[1]: Started gunicorn daemon.
Aug 14 12:36:57 tmpgmv systemd[439]: gunicorn.service: Failed to execute command: Permission denied
Aug 14 12:36:57 tmpgmv systemd[439]: gunicorn.service: Failed at step EXEC spawning /home/pcask/pcask/venv/lib/python3.8/site-packages/gunicorn: Permission denied
Aug 14 12:36:57 tmpgmv systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Aug 14 12:36:57 tmpgmv systemd[1]: gunicorn.service: Failed with result 'exit-code'. 1 Answer
systemd uses its own logging. The command for viewing it is
journalctl You can use
journalctl -u gunicorn.serviceto trace a specific service.
Some other examples:
journalctl --since="2020-01-01 10:00:00"
journalctl --since "30 min ago"
journalctl _PID=1000make sure the service is active. Check
sudo systemctl status gunicorn.serviceand if inactive you can usesudo systemctl enable gunicornto make it active.make sure the service starts after all other required services are started. Starting gunicon before nginx or your network is up wont work. Something worth noting: your unit is lacking a
After=network.targetin the[UNIT]section.
Assuming your gunicorn works when manually started you do not need the nginx logs but just in case those are:
/var/log/nginx/access.log
/var/log/nginx/error.log 3