0

I'm trying to run daphne 2.1 using multiprocessing. In the documentation I have:

If you want to bind multiple Daphne instances to the same port on a machine, use a process supervisor that can listen on ports and pass the file descriptors to launched processes, and then pass the file descriptor with --fd NUM.

I tried to this with a socket (dapnhe.socket):

[Unit]
Description=Daphne Socket worker %i

[Socket]
ListenStream=/usr/local/reduction/dist/daphne.sock
Accept=yes

[Install]
WantedBy=sockets.target

And with a service (daphne@.service)

[Unit]
Description=Daphne Service For Django %I
After=syslog.target

Requires=daphne.socket

[Service]
Type=simple
RuntimeDirectory=daphne
PIDFile=/run/daphne.pid
WorkingDirectory=/usr/local/reduction/src

ExecStartPre=/bin/bash -c 'systemctl set-environment FD=`echo %i | tr -d -`'
ExecStart=/bin/bash -c '/usr/local/reduction/venv/bin/daphne -fd ${FD} server.asgi:application'

Restart=always

[Install]
WantedBy=multi-user.target

The %i has the form %d-%d-%d. I'm just removing the - before passing it to daphne.

This doesn't work... Anyone knows how to pass an FD to daphne?

RicLeal
  • 923
  • 9
  • 23
  • I don't find the daphne docs clear. I suggest asking the daphne project for an example of using systemd like this. – Mark Stosberg May 03 '18 at 12:53
  • You haven't explained what behavior you observe from this (in particular, how it differs from your expectation). That would be good information to include. Can you edit your question to include it? – Jean-Paul Calderone May 03 '18 at 12:56
  • Also, can you clarify the purpose of setting FD to a string transformation of `%i`? If I am reading systemd docs correctly, %i is the systemd "instance name". I don't see how the instance name could possibly be the right value to supply as a file descriptor argument. – Jean-Paul Calderone May 03 '18 at 12:59
  • I asked the Daphne developers. No replies so far. In fact this FD parameter is part of twisted. It must be an integer. I played with the %i to see if I could get and integer. The original format of %i is --. Here the discussion in daphne issues: https://github.com/django/daphne/issues/182#issuecomment-384791173 In the end my questions and the output of systemd. – RicLeal May 03 '18 at 13:46

0 Answers0