Search code examples
gunicornsupervisord

Run gunicorn as fcgi-program in supervisord


I'd like to try running gunicorn on a socket managed by supervisor. Supervisor can manage sockets and passes the file descriptor to the child process on stdin (http://supervisord.org/configuration.html#fcgi-program-x-section-settings). Gunicorn can accept a file descriptor to bind to as an argument (https://docs.gunicorn.org/en/stable/settings.html#bind), e.g. gunicorn wcgi:app -b fd://FD

I wrote a script to capture the stdin and pass it as an argument to gunicorn:

input=$(cat)
gunicorn seagull.ui.app:server -b "${input}"

In the logs from the child process, I see this:

[2022-07-26 09:34:35 +0100] [696696] [ERROR] Can't connect to ('0.0.0.0', 8000)
cat: -: Transport endpoint is not connected
[2022-07-26 09:34:38 +0100] [696731] [INFO] Starting gunicorn 20.1.0
[2022-07-26 09:34:38 +0100] [696731] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2022-07-26 09:34:38 +0100] [696731] [ERROR] Retrying in 1 second.

Have I missed something to make this work?


Solution

  • The answer turns out to be gunicorn -b fd://0 wcgi:app, since the supervisord socket manager passes the open socket to child processes on file decsriptor 0.

    It doesn't seem to make that much sense to use gunicorn with supervisord socket manager, since they are then both managing sockets and workers. chaussette seems to be an alternative so that supervisord can manage all sockets and workers