Question

gunicorn is not running

Posted June 4, 2021 105 views
NginxDigitalOceanPythonDjangoDeploymentInitial Server Setup

As i am following through the tutorial of

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04

gunicorn is not running

when i used the command
sudo systemctl status gunicorn

my gunicorn.socket file

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

my gunicorn.service file

developer@ubuntu-s-1vcpu-1gb-blr1-01:~$ sudo nano /etc/systemd/system/gunicorn.service

GNU nano 4.8 
                                                /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=developer
Group=www-data
WorkingDirectory=/home/developer/myprojectdir
ExecStart=/home/developer/myprojectdir/myprojectenv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          bharathwajan.wsgi:application

[Install]
WantedBy=multi-user.target

error comes when i try to check the status of gunicorn by the command

sudo systemctl status gunicorn

Error:

gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2021-06-04 03:53:42 UTC; 48min ago
TriggeredBy: ● gunicorn.socket
   Main PID: 51351 (code=exited, status=1/FAILURE)

Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]:     self.stop()
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]:   File "/home/developer/myprojectdir/myprojectenv/lib/python3.8/site-packages/gunicorn/arbiter.py>
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]:     time.sleep(0.1)
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]:   File "/home/developer/myprojectdir/myprojectenv/lib/python3.8/site-packages/gunicorn/arbiter.py>
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]:     self.reap_workers()
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]:   File "/home/developer/myprojectdir/myprojectenv/lib/python3.8/site-packages/gunicorn/arbiter.py>
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[51351]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Jun 04 03:53:42 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
lines 1-16/16 (END)

edited by bobbyiliev

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,

When checking the Gunicorn application logs, do you get any other errors?

sudo journalctl -u gunicorn

Also I could suggest checking the Gunicorn socket logs by typing the following command:

sudo journalctl -u gunicorn.socket

Feel free to share the logs here as well.

Regards,
Bobby

  • when i tried

    sudo journelctl -u gunicorn.socket
    

    i got the below result

     Logs begin at Mon 2021-05-31 02:03:42 UTC, end at Fri 2021-06-04 14:25:20 UTC. --
    Jun 02 11:04:28 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 11:06:38 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 11:12:10 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 15:01:32 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 15:15:35 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 15:18:37 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    -- Reboot --
    Jun 02 15:20:08 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 15:22:28 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 15:23:31 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 15:43:25 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 15:46:44 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 15:47:18 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 16:25:37 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 16:26:29 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 16:28:39 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket.
    Jun 02 16:31:42 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 17:17:28 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gt.unicorn socket.
    Jun 02 17:18:10 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: gunicorn.socket: Failed with result 'service-start-limit-hit'.
    Jun 02 17:19:33 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Listening on gunicorn socket
    

    when i used

    sudo journalctl -u gunicorn
    
    

    i got the following error

    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Started gunicorn daemon.
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195799]: [2021-06-02 11:06:35 +0000] [195799] [INFO] Starting gunicorn 20.1.0
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195799]: [2021-06-02 11:06:35 +0000] [195799] [INFO] Listening at: unix:/run/gunicorn.sock >
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195799]: [2021-06-02 11:06:35 +0000] [195799] [INFO] Using worker: sync
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]: [2021-06-02 11:06:35 +0000] [195811] [INFO] Booting worker with pid: 195811
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]: [2021-06-02 11:06:35 +0000] [195811] [ERROR] Exception in worker process
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]: Traceback (most recent call last):
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     worker.init_process()
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     self.load_wsgi()
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     self.wsgi = self.app.wsgi()
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     self.callable = self.load()
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     return self.load_wsgiapp()
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     return util.import_app(self.app_uri)
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     mod = importlib.import_module(module)
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:     return _bootstrap._gcd_import(name[level:], package, level)
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]:   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
    Jun 02 11:06:35 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]: ModuleNotFoundError: No module named 'bharathwajan.wsgi'
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]: [2021-06-02 11:06:35 +0000] [195812] [INFO] Booting worker with pid: 195812
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195811]: [2021-06-02 11:06:36 +0000] [195811] [INFO] Worker exiting (pid: 195811)
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195813]: [2021-06-02 11:06:36 +0000] [195813] [INFO] Booting worker with pid: 195813
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]: [2021-06-02 11:06:36 +0000] [195812] [ERROR] Exception in worker process
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]: Traceback (most recent call last):
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]:     worker.init_process()
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]:     self.load_wsgi()
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]:   File "/home/bharathwajan/bharathwajan/django/lib/python3.8/site-packages/gunicor>
    Jun 02 11:06:36 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[195812]:     self.wsgi = self.app.wsgi()
    lines 1-39
    
    

    when i used

     sudo journalctl -u gunicorn
    
    

    i got the above error saying no module named bharathwajan.wsgi
    but i used

    gunicorn --bind 0.0.0.0:8000 bharathwajan.wsgi:application