Question

Gunicorn fails to start through systemd

Posted July 16, 2021 266 views
DjangoUbuntu 20.04

Hey, I’m trying to get a django app that I’ve made work on the droplet, but I’m getting a really annoying issue with starting gunicorn through systemd

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

and everything works as intented, till I test the socket activation

after typing in systemctl status gunicorn I get hit with this error message

● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2021-07-16 10:19:26 UTC; 25min ago
TriggeredBy: ● gunicorn.socket
    Process: 1769 ExecStart=/home/basic/project/projectenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock myapp.wsgi:application (code=exited, stat>
   Main PID: 1769 (code=exited, status=217/USER)

Jul 16 10:19:26 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1]: Started gunicorn daemon.
Jul 16 10:19:26 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1769]: gunicorn.service: Failed to determine user credentials: No such process
Jul 16 10:19:26 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1769]: gunicorn.service: Failed at step USER spawning /home/basic/project/projectenv/bin/gunicorn: No such process
Jul 16 10:19:26 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1]: gunicorn.service: Main process exited, code=exited, status=217/USER
Jul 16 10:19:26 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1]: gunicorn.service: Failed with result 'exit-code'.

seeing the logfile with gunicorn –log-file=- myapp.wsgi:aplication gives me

[2021-07-16 10:47:20 +0000] [2260] [INFO] Starting gunicorn 20.1.0
[2021-07-16 10:47:20 +0000] [2260] [INFO] Listening at: http://127.0.0.1:8000 (2260)
[2021-07-16 10:47:20 +0000] [2260] [INFO] Using worker: sync
[2021-07-16 10:47:20 +0000] [2262] [INFO] Booting worker with pid: 2262
[2021-07-16 10:47:20 +0000] [2262] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/home/basic/.local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/home/basic/.local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/home/basic/.local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/basic/.local/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/basic/.local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/home/basic/.local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/basic/.local/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
    mod = importlib.import_module(module)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/basic/project/app/wsgi.py", line 12, in <module>
    from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
[2021-07-16 10:47:20 +0000] [2262] [INFO] Worker exiting (pid: 2262)
[2021-07-16 10:47:20 +0000] [2260] [INFO] Shutting down: Master
[2021-07-16 10:47:20 +0000] [2260] [INFO] Reason: Worker failed to boot.

Any ideas what might be wrong?

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

I’ve managed to find my issues. I was editing a gunicorn.service file in systemd, while I should have done it in systemd/system. Sloppy mistake