Score:0

gunicorn.service: Failed with result 'exit-code'

in flag

I want to use a digitalocean droplet to host a django site. I'm trying to get the app running on the server with gunicorn and nginx, I'm getting a 502 error when I try to hit the server from my browser and I've been trying to figure out what's going on.

I have been following this tutorial. My droplet is Ubuntu 20.04.

This is my /etc/systemd/system/gunicorn.socket:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

This is my /etc/systemd/system/gunicorn.service:

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

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

[Install]
WantedBy=multi-user.target

I can run gunicorn --bind 0.0.0.0:8000 mysite.wsgi and python manage.py runserver with no errors showing up. When I run sudo systemctl status gunicorn.socket, the socket appears to be active.

However, when I run sudo systemctl status gunicorn, I get the following:

● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2023-03-14 05:25:01 UTC; 4min 53s ago
TriggeredBy: ● gunicorn.socket
    Process: 74292 ExecStart=/home/root/mysite/venv/bin/gunicorn --access-logfile - --workers 3 --bind>
   Main PID: 74292 (code=exited, status=200/CHDIR)

Mar 14 05:25:01 mysite systemd[1]: Started gunicorn daemon.
Mar 14 05:25:01 mysite systemd[1]: gunicorn.service: Main process exited, code=exited, status=200>
Mar 14 05:25:01 mysite systemd[1]: gunicorn.service: Failed with result 'exit-code'.

I am using gunicorn version 20.0.2. s

From looking at the nginx error logs, I keep getting the following error when I try to access the site:

2023/03/14 05:12:12 [error] 72896#72896: *22 connect() to unix:/run/gunicorn.sock failed 

(111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx,server

mysite.dev, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", 

host: "xxx.xx.xxx.xxx"

Any help is appreciated! Thank you!

hr flag
The tutorial says to use `User=yourusername` and `WorkingDirectory=/home/yourusername/path-to-your-projectdir` yet you are using `User=root` and `WorkingDirectory=/home/root/mysite` - these are not directly analogous since root's home directory (at least by default) is `/root` not `/home/root`.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.