I currently have this log/run script as part of a runit service:

set -e

exec svlogd -tt ./main

If I "tail -f log/main/current", I don't see the service output written in "real time." It seems to only dump the stdout in 4K increments. So if the service is used lightly, I can't see the most recent log data, unless I actually do an 'sv restart' on the service, in which case all data is written to the logs before the service is restarted.

I've played around with the "-l" and "-b" arguments, but these did not have any effect (and I'm not even sure it matters at this point).


It look like the fault unfortunately lies in the daemon which does not flush it's stdout after writing the log data.

svlogd does only line buffering so it outputs complete lines to the log file as soon as they arrive on stdin.

| improve this answer | |
  • The thing is, if I restart the service with "sv restart", then the log is written immediately. I believe this suggests that the daemon is flushing to stdout, but runit is not actually writing it to disk. Something in the runit logger seems to be holding the data until forcefully told to write. – up_the_irons Feb 28 '12 at 20:52
  • 1
    I would assume that sending TERM to the daemon flushes its stdio output buffers as a part of the atexit routines, no? You may try sending KILL and see if it changes the situation. – jpc Mar 2 '12 at 13:50
  • jpc, you're right. When I send KILL, anything that was not written is simply lost. So I suppose the TERM is flushing the stdio output buffer. I need to investigate manual flushing within the daemon... – up_the_irons Mar 31 '12 at 3:17
  • 2
    Adding "$stdout.flush" after a "puts" within the daemon (a Ruby process) fixes this problem! :) – up_the_irons Mar 31 '12 at 3:21
  • 1
    $stdout.sync = true for Ruby. – W. Andrew Loe III Dec 18 '14 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.