skip to Main Content

I’ve followed this guide (https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04), but I’m presently seeing the following when trying to run gunicorn via the gunicorn service file (/etc/systemd/system/gunicorn.service):

Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]:   File "/opt/envs/automation-console-env/bin/gunicorn", line 5, in <module>
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]:     from gunicorn.app.wsgiapp import run
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]: ModuleNotFoundError: No module named 'gunicorn'

The gunicorn.service file contains the following:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/opt/envs/automation-console-env
ExecStart=/opt/envs/automation-console-env/bin/gunicorn --timeout 600 --log-level debug --error-log /var/log/automation-console-env_error.log  --access-logfile /var/log/automation-console-env_access.log --workers 3 --bind unix:/opt/envs/automation-console-env/automation-console-env.sock django_forms.wsgi:application


[Install]
WantedBy=multi-user.target

Running gunicorn manually works fine:

gunicorn –bind 0.0.0.0:8000 myproject.wsgi

This was previously working before I had to upgrade my Python version from 3.5.2 to 3.9, and due to some issues I ended up having to recreate the virtual environment, so I don’t think it’s necessarily an issue with the service file, but rather my Python/Gunicorn installation.

If anyone could offer some advice, it would be greatly appreciated 🙂

2

Answers


  1. Does the automation-console-env environment exist? If so, is gunicorn installed there? In either case, since it is working as gunicorn ... on the command line, you should be able to use this installation.

    which gunicorn
    

    Then change your systemd unit file to point to this executable.

    Login or Signup to reply.
  2. It seems that you either are defining the wrong path or you might be facing a permission issue in gunicorn.service.

    First try to enable the service by using systemctl enable gunicorn.service. If it didn’t work, then try the following:

    Edit gunicorn.service as follows:

    from: --bind unix:/opt/envs/automation-console-env/automation-console-env.sock django_forms.wsgi:application

    to: --bind unix:/opt/envs/automation-console-env/automation-console-env.sock django_forms.wsgi

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search