Score:1

Django + Nginx, and Gunicorn: doesn't create gunicorn.sock

mx flag

I have error when i do systemctl start gunicorn.socket

systemctl status gunicorn.socket
● gunicorn.socket - gunicorn socket
     Loaded: error (Reason: Unit gunicorn.socket failed to load properly: Bad message.)
     Active: inactive (dead)

Sep 17 14:20:52 tcs-generator systemd[1]: /etc/systemd/system/gunicorn.socket:3: Invalid section header '[Socket]ListenStream=/run/gunicorn.sock'

My SystemD Unit file (gunicorn.service):

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/Network_web
ExecStart=/var/www/Network_web/djangoenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock          Network_web.wsgi:application
[Install]
WantedBy=multi-user.target

My socket file (gunicorn.socket):

[Unit]
Description=gunicorn socket
[Socket]ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target

This is some of the output we see:

root@tcs-generator:/# ls -la /run/ | grep gu
root@tcs-generator:/#

Sep 17 17:18:28 tcs-generator systemd[1]: Started gunicorn daemon.
Sep 17 17:18:31 tcs-generator gunicorn[858]: usage: gunicorn [OPTIONS] [APP_MODULE]
Sep 17 17:18:31 tcs-generator gunicorn[858]: gunicorn: error: argument -b/--bind: expected one argument
Sep 17 17:18:31 tcs-generator systemd[1]: gunicorn.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Sep 17 17:18:31 tcs-generator systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Sep 17 14:20:52 tcs-generator systemd[1]: /etc/systemd/system/gunicorn.service:10: Missing '=', ignoring line.
Score:2
ru flag

You aren't far off, you simply forgot to separate your section header and your file in the socket file's config.

Like this:

[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target

Note that this is just a simple typo on your end - section headers belong on their own lines and then the config underneath that header on separate lines.

If this still doesn't work, consult the SystemD manual to see when that function was put into place to make sure that your SystemD supports those config options.

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.