I'm trying to deploy a Django project on Ubuntu server. I'm folwing this guide.
But I'm facing a problem when I run this command sudo systemctl status gunicorn
, I get this error:
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2021-08-31 20:53:12 UTC; 6min ago
TriggeredBy: ● gunicorn.socket
Process: 1918 ExecStart=/home/houssem/project/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock config.wsgi:application (code=exited, >
Main PID: 1918 (code=exited, status=3)
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: ModuleNotFoundError: No module named 'django_extensions'
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: [2021-08-31 20:53:12 +0000] [1932] [INFO] Worker exiting (pid: 1932)
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [WARNING] Worker with pid 1931 was terminated due to signal 15
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [WARNING] Worker with pid 1932 was terminated due to signal 15
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [INFO] Shutting down: Master
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [INFO] Reason: Worker failed to boot.
Aug 31 20:53:12 ubuntu-20-lts systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Aug 31 20:53:12 ubuntu-20-lts systemd[1]: gunicorn.service: Failed with result 'exit-code'.
When I run this command gunicorn config.wsgi:application --preload -b 0.0.0.0:8000
it works fine and I can access the site using the IP address.
My gunicorn.service
and /etc/systemd/system/gunicorn.socket
files look like this:
# /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myprojectdir
ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
myproject.wsgi:application
[Install]
WantedBy=multi-user.target
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
All the mentioned (in the guide) commands related to gunicorn before this one sudo systemctl status gunicorn
work as expected and print the same output as in the guide.
I searched for solutions but I can't figure out how to fix this issue, I'm new to gunicorn.
So please can anyone help me to fix this?
I can provide more detail if the provided information is not enough.
EDIT
About the packages, I've already installed the packages in the virtualenv from a requirements.txt file: pip install -r requirements.txt
. Also, I've installed the django-extension globally but still have the same error.