57

I am planning to run multiple processes using supervisor and please find my supervisord.conf file below:

[supervisord]

[program:bash]
command=xyz
stdout_logfile =/tmp/bash.log
redirect_stderr=true

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

I wish to redirect the stdout of the process named bash to supervisor console so that when i start supervisor using

/usr/bin/supervisord

command, i could see the child process logs. How can i do this ? I tried putting syslog for stdout_logfile attribute but it did not work.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
cucucool
  • 3,777
  • 8
  • 48
  • 63
  • Can you clarify what is your problem? Is it perhaps because you didn't specify `bash` in your `command=` line? – nodakai Aug 08 '14 at 07:40
  • xyz could be any command. The problem i am facing is i am trying to view the child process logs in the supervisord console. For example, if the command was a list command, i would like to see its output in the supervisord console. – cucucool Aug 08 '14 at 15:34

1 Answers1

116

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
  • 7
    I found interesting to share that `/proc/self/fd/1` is actually a symlink to `/dev/stdout`, when a process opens that file, the system actually clones file descriptor #1 (stdout) of that process. – Carlos Quijano Dec 19 '17 at 01:25
  • 1
    Actually, `/dev/stdout` is a symlink to `/proc/self/fd/1` and `/dev/fd/1` a symlink to whatever `/dev/pts/#` the process is communicating on, but it all works out roughly the same. – mVChr May 15 '19 at 22:31