6

I'm using supervisord as the entry point for Docker containers as described in https://docs.docker.com/articles/using_supervisord/, I want all logs to be written to stdout so I can take advantage of builtin tools like docker logs or systemd's journal, especially if running the containers on CoreOS.

for stderr there's redirect_stderr=true option for subprocesses, is it possible to redirect the subprocess stdout back to supervisord somehow and not deal with actual log files ?

Gal Ben-Haim
  • 17,433
  • 22
  • 78
  • 131
  • As supervisor is a daemon, I'm not sure "stdout" has any real meaning - it is not attached to a terminal or anywhere useful. Nor would anything receiving the output be able to distinguish which output came from which sub-process, which would severely limit its usefulness. Perhaps what you actually need is a way of piping each output to a command, perhaps using named pipes (FIFOs)? – IMSoP Oct 04 '14 at 12:23
  • 1
    actually, if its used as the entry point for a Docker container its running in the foreground – Gal Ben-Haim Oct 04 '14 at 12:40
  • Hm, possibly. The point about all the outputs being merged together stands, though. It seems like the real question is "can I make supervisor child processes log to service X rather than a file?" – IMSoP Oct 04 '14 at 13:03
  • https://github.com/ddollar/foreman is actually doing a pretty good job in merging the logs to stdout, the problem with it is that its not meant to be run in production and it doesn't handle restarts of child processes if they crash – Gal Ben-Haim Oct 04 '14 at 16:16

1 Answers1

7

You can redirect the program's stdout to supervisor's stdout using the following configuration options:

stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0

Explanation:

  • When a process opens /dev/fd/1 (which is the same as /proc/self/fd/1), the system actually clones file descriptor #1 (stdout) of that process. Using this as stdout_logfile therefore causes supervisord to redirect the program's stdout to its own stdout.
  • stdout_logfile_maxbytes=0 disables log file rotation which is obviously not meaningful for stdout. Not specifying this option will result in an error because the default value is 50MB and supervisor is not smart enough to detect that the specified log file is not a regular file.

For more information:

http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
  • `redirect_stderr=true` is also really useful here (redirects the stderr into stdout on the program) – Tim Tisdall Apr 27 '16 at 15:22
  • Unfortunately on Linux 4 Tegra this gives `spawnerr: unknown error making dispatchers for 'ssh-forward_00': ENXIO` for me. Couldn't find a workaround. – Heath Raftery Jul 11 '19 at 05:31