Gunicorn not starting even after succesfully configuring all files

128 Views Asked by At

I am working on a particular Django project (Don't know if this makes a difference but the service provider is Hostinger).. The deployment of the same is to be done on a vps server with ubuntu in it. Using gunicorn and nginx is what I have planned , but I keep on running into

502 bad gateway error On poking around found that gunicorn is not starting

The following is the error received when I ran

sudo systemctl status gunicorn

Error :

× gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2024-01-02 07:53:47 UTC; 4 days ago
TriggeredBy: ● gunicorn.socket
   Main PID: 6153 (code=exited, status=203/EXEC)
        CPU: 1ms

Jan 02 07:53:47 srv457341 systemd[1]: Started gunicorn daemon.
Jan 02 07:53:47 srv457341 systemd[6153]: gunicorn.service: Failed to execute /root/Assistanza/Assistanza/env/bin/gunicorn: No such file or directory
Jan 02 07:53:47 srv457341 systemd[6153]: gunicorn.service: Failed at step EXEC spawning /root/Assistanza/Assistanza/env/bin/gunicorn: No such file or directory
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Start request repeated too quickly.
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jan 02 07:53:47 srv457341 systemd[1]: Failed to start gunicorn daemon.

The following is my file structure : enter image description here

The path to this is : /root/Assistanza/Assistanza

The following is the service file of gunicorn:

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

[Service]
User=root
Group=www-data
WorkingDirectory=/root/Assistanza/Assistanza
ExecStart=/root/Assistanza/Assistanza/env/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          Assistanza.wsgi:application

[Install]
WantedBy=multi-user.target
~                                                                                                                                                                       ~        

How do I solve this ?

Update : So the error was the gunicorn was not running right in the virtual environment. To solve this I installed a new virtual environment and then installed gunicorn in that and saw that which gunicorn gave me the path to the file/env/bin/gunicorn.

and changed the service file path to this new venv and all is working fine.

1

There are 1 best solutions below

4
Proud Wadhwa On BEST ANSWER

This error message states that gunicorn module isn't installed on your env. Activate your env and execute these commands:

pip install gunicorn

you need to install gunicorn.

If you have already installed gunicorn you may use [while being in env]:

which gunicorn

If it shows your env path, then your env is all-correct if not the env may be corrupted. Consider creating new virtual environment by using:

deactivate
virtualenv env

and install the requirements... If the error is still there consider checking the file path & permissions.

I recommend to go through this document: DIGITALOCEAN-UBUNTU1604.

Until there is a .sock file in your folder, your gunicorn isn't running fine.

Hope this helped you!