Can't connect to /home/ubuntu/env/Project/Project.sock - django

Am trying to host a we application using gunicorn and nginx. But I cant start the gunicorn service. everytime am getting the error message.
This is the error am getting
(env) root#ip-172-31-21-54:/home/env# sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2018-12-17 14:59:42 UTC; 488ms ago
Process: 14160 ExecStart=/home/ubuntu/env/bin/gunicorn --access-logfile - --
workers 3 --bind unix:/home/ubuntu/env/Project/Project.sock
Project.wsgi:application (code=exited, status=1/FAILURE)
Main PID: 14160 (code=exited, status=1/FAILURE)
Dec 17 14:59:36 ip-172-31-21-54 systemd[1]: Started gunicorn daemon.
Dec 17 14:59:37 ip-172-31-21-54 gunicorn[14160]: [2018-12-17 14:59:37 +0000]
[14160] [INFO] Starting gunicorn 19.9.0
Dec 17 14:59:37 ip-172-31-21-54 gunicorn[14160]: [2018-12-17 14:59:37 +0000]
[14160] [ERROR] Retrying in 1 second.
Dec 17 14:59:38 ip-172-31-21-54 gunicorn[14160]: [2018-12-17 14:59:38 +0000]
[14160] [ERROR] Retrying in 1 second.
Dec 17 14:59:39 ip-172-31-21-54 gunicorn[14160]: [2018-12-17 14:59:39 +0000]
[14160] [ERROR] Retrying in 1 second.
Dec 17 14:59:40 ip-172-31-21-54 gunicorn[14160]: [2018-12-17 14:59:40 +0000]
[14160] [ERROR] Retrying in 1 second.
Dec 17 14:59:41 ip-172-31-21-54 gunicorn[14160]: [2018-12-17 14:59:41 +0000] [14160] [ERROR] Retrying in 1 second.
Dec 17 14:59:42 ip-172-31-21-54 gunicorn[14160]: [2018-12-17 14:59:42 +0000] [14160] [ERROR] Can't connect to /home/ubuntu/env/Project/Project.sock
Dec 17 14:59:42 ip-172-31-21-54 systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Dec 17 14:59:42 ip-172-31-21-54 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
And My gunicorn.service file is
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/env/Project
ExecStart=/home/ubuntu/env/bin/gunicorn --access-logfile -
--workers 3 --bind unix:/home/ubuntu/env/Project/Project.sock
Project.wsgi:application
[Install]
WantedBy=multi-user.target
I cant find the error.. Please help me to solve this.

Related

When I start gounicorn.services, I get error 200/CHDIR. How can it be corrected?

gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=root
WorkingDirectory=/var/www/botproject/
ExecStart=gunicorn --workers 5 --bind unix:/run/gunicorn.sock botproject.wsgi:application
[Install]
WantedBy=multi-user.target
/var/www/botproject/ - project folder
systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2022-07-09 21:28:04 UTC; 3s ago
Process: 83314 ExecStart=/usr/local/bin/gunicorn --workers 5 --bind unix:/run/gunicorn.sock botproject.wsgi:application > Main PID: 83314 (code=exited, status=200/CHDIR)
Jul 09 21:28:04 server.domain.com systemd[1]: Started gunicorn daemon.
Jul 09 21:28:04 server.domain.com systemd[1]: gunicorn.service: Main process exited, code=exited, status=200/CHDIR
Jul 09 21:28:04 server.domain.com systemd[1]: gunicorn.service: Failed with result 'exit-code'.
I can't figure out what is causing the 200/CHDIR error
I would start debugging by trying to run the ExecStart command manually, and see if that works (or what error you get):
$ cd /var/www/botproject/
$ sudo gunicorn --workers 5 --bind unix:/run/gunicorn.sock botproject.wsgi:application

502 Bad Gateway nginx/1.14.0 (Ubuntu) Django

Well I've depoloyed my Django application on DigitalOcean, and used domain which I bought. Now instead of default application page it shows 502 Bad Gateway
nginx/1.14.0 (Ubuntu). And nginx errors log returns such error:
*4 connect() to unix:/home/username/project.sock failed (111: Connection refused) while connecting to upstream, client: 82.194.22.116, server: challenge.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/username/project.sock:/", host: "challenge.com"
my nginx configurations:
server {
listen 80;
server_name challenge.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/username;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/username/ccproject.sock;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
}
}
my settings in ``settings.py```:
ALLOWED_HOSTS = ['64.225.1.249', 'challenge.com']
And my socket file is in /home/username/
gunicorn status:
(env) progbash#challengers:~/ccproject$ sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2019-12-12 10:27:02 UTC; 1min 56s ago
Process: 29262 ExecStart=/home/username/ccproject/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/username/ccproject.sock
Main PID: 29262 (code=exited, status=1/FAILURE)
Dec 12 10:26:57 challenge systemd[1]: Started gunicorn daemon.
Dec 12 10:26:57 challenge gunicorn[29262]: [2019-12-12 10:26:57 +0000] [29262] [INFO] Starting gunicorn 20.0.4
Dec 12 10:26:57 challengers gunicorn[29262]: [2019-12-12 10:26:57 +0000] [29262] [ERROR] Retrying in 1 second.
Dec 12 10:26:58 challenge gunicorn[29262]: [2019-12-12 10:26:58 +0000] [29262] [ERROR] Retrying in 1 second.
Dec 12 10:26:59 challengers gunicorn[29262]: [2019-12-12 10:26:59 +0000] [29262] [ERROR] Retrying in 1 second.
Dec 12 10:27:00 challenge gunicorn[29262]: [2019-12-12 10:27:00 +0000] [29262] [ERROR] Retrying in 1 second.
Dec 12 10:27:01 challenge gunicorn[29262]: [2019-12-12 10:27:01 +0000] [29262] [ERROR] Retrying in 1 second.
Dec 12 10:27:02 challenge gunicorn[29262]: [2019-12-12 10:27:02 +0000] [29262] [ERROR] Can't connect to /home/username/ccproject.sock
Dec 12 10:27:02 challenge systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Dec 12 10:27:02 challenge systemd[1]: gunicorn.service: Failed with result 'exit-code'.
How did your unix socket came to life? Do you have /etc/systemd/system/gunicorn.socket script as per here: https://docs.gunicorn.org/en/stable/deploy.html

Gunicorn not starting throwing gunicorn.service: Failed with result 'exit-code'. error

I'm trying a deploy simple Django application on Digital Ocean by following this [link][1] I follow every work step by step and successfully run that project via python manage.py runserver where it's not throwing any error but when I try to implement it with gunicorn its throw following error
gunicorn.service: Failed with result 'exit-code'.
Here is my following configuration:
sudo nano /etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
sudo nano /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=pos
Group=www-data
WorkingDirectory=/home/pos/pos
ExecStart=/home/pos/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
pos.wsgi:application
[Install]
WantedBy=multi-user.target
sudo systemctl status gunicorn.socket
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: active (listening) since Tue 2019-11-26 07:39:39 UTC; 12min ago
Listen: /run/gunicorn.sock (Stream)
CGroup: /system.slice/gunicorn.socket
Nov 26 07:39:39 POS systemd[1]: Listening on gunicorn socket.
When I try to start gunicorn it's throwing this error
sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-11-26 07:39:43 UTC; 13min ago
Process: 718 ExecStart=/home/pos/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock pos.wsgi:application (code=exited, status=1/FAILURE)
Main PID: 718 (code=exited, status=1/FAILURE)
Nov 26 07:39:43 POS gunicorn[718]: Arbiter(self).run()
Nov 26 07:39:43 POS gunicorn[718]: File "/home/pos/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 198, in run
Nov 26 07:39:43 POS gunicorn[718]: self.start()
Nov 26 07:39:43 POS gunicorn[718]: File "/home/pos/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 155, in start
Nov 26 07:39:43 POS gunicorn[718]: self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
Nov 26 07:39:43 POS gunicorn[718]: File "/home/pos/env/lib/python3.7/site-packages/gunicorn/sock.py", line 172, in create_sockets
Nov 26 07:39:43 POS gunicorn[718]: sock_name = sock.getsockname()
Nov 26 07:39:43 POS gunicorn[718]: OSError: getsockaddrlen: bad family
Nov 26 07:39:43 POS systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Nov 26 07:39:43 POS systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Anyone helps me to solve this issue?
[1]: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04
The latest version of gunicorn (20.0.3) can cause this problem.
Try installing an older version of gunicorn:
pip install gunicorn==20.0.2
It seems that you are trying to listen to unix:/run/gunicorn.sock in ExecStart, but the socket is at run/gunicorn.socket. Try changing this and run systemctl daemon-reload to see if it makes a difference.

How to set up django project with gunicorn service on gunicorn.socket?

I'm trying to run my django project on gunicorn socket as service. But it fails to start; Can anybody help me with this?
I tried by following this link: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04
I'm also using virtualenvwrapper to manage my virtualenvs.
Here is my configuration files:
/etc/systemd/system/gunicorn.socket:
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
/etc/systemd/system/gunicorn.service:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=mohsen
Group=www-data
WorkingDirectory=/home/mohsen/Desktop/SummerCampDocs/carpooling/carpooling
ExecStart=/home/mohsen/.virtualenvs/carpooling/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock carpooling.wsgi:application
[Install]
WantedBy=multi-user.target
By running this commands:
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
sudo systemctl status gunicorn
I get the following message:
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2019-08-28 12:38:18 +0430; 33min ago
Process: 14000 ExecStart=/home/mohsen/.virtualenvs/carpooling/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock carpooling.wsgi:application (code=exited, status=1/FAILURE)
Main PID: 14000 (code=exited, status=1/FAILURE)
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: self.stop()
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: File "/home/mohsen/.virtualenvs/carpooling/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: time.sleep(0.1)
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: File "/home/mohsen/.virtualenvs/carpooling/lib/python3.6/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: self.reap_workers()
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: File "/home/mohsen/.virtualenvs/carpooling/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
Aug 28 12:38:18 mohsen-ThinkPad-T490 gunicorn[14000]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
Aug 28 12:38:18 mohsen-ThinkPad-T490 systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Aug 28 12:38:18 mohsen-ThinkPad-T490 systemd[1]: gunicorn.service: Failed with result 'exit-code'.

Gunicorn not running can't connect to sock file

I've got a gunicorn script that fails to load.
Here's it's code
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/revamp
ExecStart=/home/sammy/revamp/revampenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/sammy/revamp/revamp.sock revamp.wsgi:application
[Install]
WantedBy=multi-user.target
and the response from status
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2017-07-19 14:17:56 UTC; 2min 1s ago
Process: 26564 ExecStart=/home/sammy/revamp/revampenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/sammy/revamp/revamp.sock revamp.wsgi:application (code=exited, status=1/FAI
Main PID: 26564 (code=exited, status=1/FAILURE)
Jul 19 14:17:51 samuel-pc gunicorn[26564]: [2017-07-19 14:17:51 +0000] [26564] [INFO] Starting gunicorn 19.7.1
Jul 19 14:17:51 samuel-pc gunicorn[26564]: [2017-07-19 14:17:51 +0000] [26564] [ERROR] Retrying in 1 second.
Jul 19 14:17:52 samuel-pc gunicorn[26564]: [2017-07-19 14:17:52 +0000] [26564] [ERROR] Retrying in 1 second.
Jul 19 14:17:53 samuel-pc gunicorn[26564]: [2017-07-19 14:17:53 +0000] [26564] [ERROR] Retrying in 1 second.
Jul 19 14:17:54 samuel-pc gunicorn[26564]: [2017-07-19 14:17:54 +0000] [26564] [ERROR] Retrying in 1 second.
Jul 19 14:17:55 samuel-pc gunicorn[26564]: [2017-07-19 14:17:55 +0000] [26564] [ERROR] Retrying in 1 second.
Jul 19 14:17:56 samuel-pc gunicorn[26564]: [2017-07-19 14:17:56 +0000] [26564] [ERROR] Can't connect to /home/sammy/revamp/revamp.sock
Jul 19 14:17:56 samuel-pc systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Jul 19 14:17:56 samuel-pc systemd[1]: gunicorn.service: Unit entered failed state.
Jul 19 14:17:56 samuel-pc systemd[1]: gunicorn.service: Failed with result 'exit-code'.
the sock file isn't created in the folder, what am I doing wrong?
Looks like the user that you are using to run gunicorn as a service (sammy) does not have permission to access the project folder.
You can check the folder permission with ls -l
To change them you can do:
sudo chown sammy:sammy /home/sammy/revamp