Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

#!/bin/sh
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).

share|improve this question

migrated from stackoverflow.com Dec 14 '11 at 4:30

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 2 down vote accepted

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.

share|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
    
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
1  
Adding "$stdout.flush" after a "puts" within the daemon (a Ruby process) fixes this problem! :) –  up_the_irons Mar 31 '12 at 3:21
    
$stdout.sync = true for Ruby. –  W. Andrew Loe III 18 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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