Question

Django app not updating after set up with Postgres, Nginx, and Gunicorn on Ubuntu 20.04

Posted September 5, 2021 79 views
NginxPostgreSQLDjangoUbuntu 20.04

I have set up a Django app successfully using a DO droplet. I following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04. After making some changes to my code, I pushed committed (pushed) them to my git repo at github. I then pulled the changes to my server using git pull origin master. I located the changed file and sudo nano it and discovered the code changes are being reflected. I then ran these two commands (sudo systemctl daemon-reload) and (sudo systemctl restart gunicorn).

I even restarted nginx. However no changes are being reflected on my website in production. The changes can be seen on myserver_IP:8000 (sudo ufw allow 8000). The same works when I use gunicorn to load the project’s WSGI module (gunicorn --bind 0.0.0.0:8000 myproject.wsgi). I have been following up on the issue on previous community answers on the same problem but none matches by specific problem.

I later ran this command (journalctl -xe) to determine if my gunicorn restarts successfully. The following is the error log I managed to retrieve:

-- A stop job for unit gunicorn.service has begun execution.
--
-- The job identifier is 22617.
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96466]: [2021-09-05 05:45:29 +0000] [96466] [INFO] Worker exiting (pid: 96466)
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96468]: [2021-09-05 05:45:29 +0000] [96468] [INFO] Worker exiting (pid: 96468)
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96467]: [2021-09-05 05:45:29 +0000] [96467] [INFO] Worker exiting (pid: 96467)
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96459]: [2021-09-05 05:45:29 +0000] [96459] [WARNING] Worker with pid 96466 was terminated due to signal 15
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96459]: [2021-09-05 05:45:29 +0000] [96459] [WARNING] Worker with pid 96467 was terminated due to signal 15
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96459]: [2021-09-05 05:45:29 +0000] [96459] [WARNING] Worker with pid 96468 was terminated due to signal 15
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96459]: [2021-09-05 05:45:29 +0000] [96459] [INFO] Shutting down: Master
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 systemd[1]: gunicorn.service: Succeeded.
-- Subject: Unit succeeded
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit gunicorn.service has successfully entered the 'dead' state.
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 systemd[1]: Stopped gunicorn daemon.
-- Subject: A stop job for unit gunicorn.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit gunicorn.service has finished.
--
-- The job identifier is 22617 and the job result is done.
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 systemd[1]: Started gunicorn daemon.
-- Subject: A start job for unit gunicorn.service has finished successfully
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit gunicorn.service has finished successfully.
--
-- The job identifier is 22617.
Sep 05 05:45:29 ubuntu-s-1vcpu-1gb-lon1-01 sudo[96504]: pam_unix(sudo:session): session closed for user root
Sep 05 05:45:30 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96507]: [2021-09-05 05:45:30 +0000] [96507] [INFO] Starting gunicorn 20.1.0
Sep 05 05:45:30 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96507]: [2021-09-05 05:45:30 +0000] [96507] [INFO] Listening at: unix:/tai/gunicorn.sock (96507)
Sep 05 05:45:30 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96507]: [2021-09-05 05:45:30 +0000] [96507] [INFO] Using worker: sync
Sep 05 05:45:30 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96523]: [2021-09-05 05:45:30 +0000] [96523] [INFO] Booting worker with pid: 96523
Sep 05 05:45:30 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96524]: [2021-09-05 05:45:30 +0000] [96524] [INFO] Booting worker with pid: 96524
Sep 05 05:45:30 ubuntu-s-1vcpu-1gb-lon1-01 gunicorn[96525]: [2021-09-05 05:45:30 +0000] [96525] [INFO] Booting worker with pid: 96525
Sep 05 05:45:37 ubuntu-s-1vcpu-1gb-lon1-01 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=6a:ce:57:14:50:be:fe:00:00:00:01:01:08:00 SRC=107.173.209.244 DST=46.101.44.106 LEN=40 TOS=0x00 PREC=0x00 TTL=2>
Sep 05 05:45:44 ubuntu-s-1vcpu-1gb-lon1-01 sshd[96526]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=61.177.173.24  user=root
Sep 05 05:45:45 ubuntu-s-1vcpu-1gb-lon1-01 sshd[96526]: Failed password for root from 61.177.173.24 port 36579 ssh2
Sep 05 05:45:48 ubuntu-s-1vcpu-1gb-lon1-01 sshd[96526]: Failed password for root from 61.177.173.24 port 36579 ssh2
Sep 05 05:45:50 ubuntu-s-1vcpu-1gb-lon1-01 sshd[96526]: Failed password for root from 61.177.173.24 port 36579 ssh2
Sep 05 05:45:51 ubuntu-s-1vcpu-1gb-lon1-01 sshd[96526]: Received disconnect from 61.177.173.24 port 36579:11:  [preauth]
Sep 05 05:45:51 ubuntu-s-1vcpu-1gb-lon1-01 sshd[96526]: Disconnected from authenticating user root 61.177.173.24 port 36579 [preauth]
Sep 05 05:45:51 ubuntu-s-1vcpu-1gb-lon1-01 sshd[96526]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=61.177.173.24  user=root
Sep 05 05:45:56 ubuntu-s-1vcpu-1gb-lon1-01 sudo[96529]:    caleb : TTY=pts/0 ; PWD=/home/caleb/escort ; USER=root ; COMMAND=/usr/bin/journalctl -xe
Sep 05 05:45:56 ubuntu-s-1vcpu-1gb-lon1-01 sudo[96529]: pam_unix(sudo:session): session opened for user root by root(uid=0)

I have also cleared by browser cache and purged my CDN cache. No changes still on my website. Please any senior to help? This problem is a real headache.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

If you change Gunicorn socket or service files, first reload the daemon:

sudo systemctl daemon-reload

And then also restart the following two:

sudo systemctl restart gunicorn.socket gunicorn.service

Let me know how it goes!
Best,
Bobby

  • Just restarting gunicorn work. I later discovered the problem was on my /etc/nginx/sites-available/myproject file.

    Before fixing the problem, my following was as follows:

    server {
        listen 80;
        server_name server_domain_or_IP;
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/sammy/**myproject**;
        }
    
        location / {
            include proxy_params;
            proxy_pass http://unix:/run/gunicorn.sock;
        }
    }
    

    After fixing the problem, the file was as follows:

    server {
        listen 80;
        server_name server_domain_or_IP;
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/sammy/**myprojectdir**;
        }
    
        location / {
            include proxy_params;
            proxy_pass http://unix:/run/gunicorn.sock;
        }
    }
    

    I had followed a certain YouTube Tutorial and combined it with this DigitalOcean Tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04

    I later discovered I should have just followed the DO Tutorial because the YouTube Tutorial was misleading somewhere. Thank you.

    by Erin Glass
    Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server is required.