4

Problem in a nutshell: systemd creates a socket on boot, but it is not possible to restart or recreate it without a reboot.

/etc/systemd/system/gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

After reboot, /run/gunicorn.sock exists and I can connect to it with sudo gunicorn3 --bind unix:/run/gunicorn.sock test.wsgi. But after taking that process down with Ctrl+C, the socket disappears and cannot be recreated via sudo systemctl start gunicorn.socket. Incidentally, sudo systemctl status gunicorn.socket still shows the socket as active and OK.

Is something wrong or are my expectations off here (I'm not yet very familiar with systemd)?

Bonus question: I've tried to make the socket owned by the www-data user by adding "User=www-data" to the [Socket] stanza of the config file, but the socket is still owned by root.root. Where's my mistake?

leggewie
  • 998
  • 6
  • 9
  • This is a good resource, I don't know if it will help you but here you go. http://manpages.ubuntu.com/manpages/bionic/man5/systemd.socket.5.html – Nate Apr 21 '20 at 13:13
  • 1
    Thank you, @NathanielSturtz. With the help of that page, at least I figured out the answer to my bonus question; The correct config parameter is `SocketUser`, not `User`. – leggewie Apr 21 '20 at 16:24
  • 1
    Generally, if there is a gunicorn.socket service unit then there should also be a gunicorn.service unit, as well. Sysmted automatically associates them if they have the same base name. You have to restart the two units together. What messages do you get when you try to start the socket? – Lee-Man Jun 12 '20 at 15:34

0 Answers0