Report this

What is the reason for this report?

Socket activation mechanism deploying Django app doesn't work

Posted on June 15, 2020

Hi all,

I’m following this Django, Postgresql, Gunicorn, NGINX toturial to the letter, but when I want to test the socket activation mechanism with curl --unix-socket /run/gunicorn.sock localhost the whole thing just stops with the error below. This is my first time deploying a Django app (even first time deploying anything btw) and I don’t know what to do from here.

Tried adjusting and troubleshooting the gunicorn.service file, but nothing seems to work.

Jun 15 14:48:01 workee-nl systemd[1]: Started gunicorn daemon.
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26878] [INFO] Starting gunicorn 20.0.4
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26878] [INFO] Listening at: unix:/run/gunicorn.sock (26878)
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26878] [INFO] Using worker: sync
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26900] [INFO] Booting worker with pid: 26900
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26900] [ERROR] Exception in worker process
Jun 15 14:48:01 workee-nl gunicorn[26878]: Traceback (most recent call last):
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
Jun 15 14:48:01 workee-nl gunicorn[26878]:     worker.init_process()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
Jun 15 14:48:01 workee-nl gunicorn[26878]:     self.load_wsgi()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
Jun 15 14:48:01 workee-nl gunicorn[26878]:     self.wsgi = self.app.wsgi()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
Jun 15 14:48:01 workee-nl gunicorn[26878]:     self.callable = self.load()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
Jun 15 14:48:01 workee-nl gunicorn[26878]:     return self.load_wsgiapp()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
Jun 15 14:48:01 workee-nl gunicorn[26878]:     return util.import_app(self.app_uri)
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
Jun 15 14:48:01 workee-nl gunicorn[26878]:     mod = importlib.import_module(module)
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
Jun 15 14:48:01 workee-nl gunicorn[26878]:     return _bootstrap._gcd_import(name[level:], package, level)
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
Jun 15 14:48:01 workee-nl gunicorn[26878]: ModuleNotFoundError: No module named 'workee.wsgi'
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26900] [INFO] Worker exiting (pid: 26900)
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26903] [INFO] Booting worker with pid: 26903
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26903] [ERROR] Exception in worker process
Jun 15 14:48:01 workee-nl gunicorn[26878]: Traceback (most recent call last):
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
Jun 15 14:48:01 workee-nl gunicorn[26878]:     worker.init_process()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
Jun 15 14:48:01 workee-nl gunicorn[26878]:     self.load_wsgi()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
Jun 15 14:48:01 workee-nl gunicorn[26878]:     self.wsgi = self.app.wsgi()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
Jun 15 14:48:01 workee-nl gunicorn[26878]:     self.callable = self.load()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
Jun 15 14:48:01 workee-nl gunicorn[26878]:     return self.load_wsgiapp()
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
Jun 15 14:48:01 workee-nl gunicorn[26878]:     return util.import_app(self.app_uri)
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/home/walter/workee/venv/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
Jun 15 14:48:01 workee-nl gunicorn[26878]:     mod = importlib.import_module(module)
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
Jun 15 14:48:01 workee-nl gunicorn[26878]:     return _bootstrap._gcd_import(name[level:], package, level)
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
Jun 15 14:48:01 workee-nl gunicorn[26878]:   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
Jun 15 14:48:01 workee-nl gunicorn[26878]: ModuleNotFoundError: No module named 'workee.wsgi'
Jun 15 14:48:01 workee-nl gunicorn[26878]: [2020-06-15 14:48:01 +0000] [26903] [INFO] Worker exiting (pid: 26903)
Jun 15 14:48:02 workee-nl gunicorn[26878]: [2020-06-15 14:48:02 +0000] [26878] [INFO] Shutting down: Master
Jun 15 14:48:02 workee-nl gunicorn[26878]: [2020-06-15 14:48:02 +0000] [26878] [INFO] Reason: Worker failed to boot.
Jun 15 14:48:02 workee-nl systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Jun 15 14:48:02 workee-nl systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jun 15 14:48:02 workee-nl systemd[1]: gunicorn.service: Start request repeated too quickly.
Jun 15 14:48:02 workee-nl systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jun 15 14:48:02 workee-nl systemd[1]: Failed to start gunicorn daemon.


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Heya,

The error message “ModuleNotFoundError: No module named ‘workee.wsgi’” suggests that your gunicorn application cannot locate your Django project’s WSGI module. Here are some possible reasons why this might be happening:

  1. Incorrect Directory Structure: Ensure your Django project directory structure is correct and your ‘workee’ application is in the correct location.

  2. Incorrect Gunicorn Configuration: You should have a Gunicorn configuration like this in your service file:

ExecStart=/path/to/your/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock workee.wsgi:application
  1. Make sure the path to the gunicorn executable in your virtual environment and the application path are correct.

  2. The WSGI Module Doesn’t Exist or Has Errors: Open your Django project and check for a file named wsgi.py in the same directory as settings.py. This file is usually auto-generated when you start a new Django project. If it doesn’t exist or has errors, gunicorn won’t be able to find your application.

  3. The Environment Doesn’t Know About Your Application: If you’re using a virtual environment, make sure it’s active when you’re starting the service. If you’re using a service file to start gunicorn, make sure the environment variables are set correctly.

  4. The PYTHONPATH is not set correctly: The PYTHONPATH is an environment variable that tells Python where to look for modules to import. If the PYTHONPATH doesn’t include your Django project’s directory, Python won’t be able to find your application. You can add this to your service file:

Environment="PYTHONPATH=/path/to/your/django/project"

Please cross-verify the points mentioned above. If the problem persists, you may need to provide more information or context about your setup.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.