'Gunicorn - ValueError: '<path_to_sock.sock>' is not a socket

I am running a simple flask application on gunicorn with nginx as proxy server. I keep getting this error, I am not able to figure out why.

I thought gunicorn takes care of creating sock file in the path I specify right? I have attached the required files for reference.

This is my python conf file -

bind = 'unix:/home/ubuntu/<app_folder>/<service name>.sock'
worker_class='gevent'
worker_connections=1000
workers=6
preload_app=True
timeout=600

I am using a systemctl service to start gunicorn -

[Unit]
Description=Gunicorn service to serve requests for <service_name>
PartOf=global_wsgi_starter.service
After=global_wsgi_starter.service
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=<path to code>
Environment="PATH=/home/ubuntu/miniconda3/envs/virtual_env/bin"
ExecStart=/home/ubuntu/miniconda3/envs/virtual_env/bin/gunicorn -c <path_to_conf.py> server:app
[Install]
WantedBy=global_wsgi_starter.service

And this is the global_wsgi_starter.service -

[Unit]
Description=Starter process for all wsgi processes.
[Service]
# The dummy program will exit
Type=oneshot
# Execute a dummy program
ExecStart=/bin/true
# This service shall be considered active after start
RemainAfterExit=yes
[Install]
# Components of this application should be started at boot time
WantedBy=multi-user.target


Solution 1:[1]

Sometimes sock files are broken by manual mistake. delete the path.sock file and generate it again

rm -rf app.sock
sudo systemctl restart app
sudo systemctl enable app

It will generate a sock file again, then restart the server.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ramesh Ponnusamy