[ale] Cooperating with logrotate

JK jknapka at kneuro.net
Fri Nov 6 13:32:08 EST 2009


Hi folks,

I have a very long-running server process that generates a lot of
log data over time. One instance is currently appending to a 9GB
logfile.  The server process opens the log file in "w" mode and
holds it open forever.

Is there any way logrotate can work nicely with this?  What I see
happening is that if I use the "copytruncate" option to logrotate,
it copies the file and truncates it (so the on-disk size is 0
until the server appends more log data).  However, the *apparent*
size remains 9GB, presumably because the server continues to append
at the current file offset, leaving a 9GB hole at the front. Next
time logrotate runs (and the file is apparently 9.5 GB), it copies
the whole 9.5GB -- but logrotate actually writes a new file with
all those nulls in it, rather than writing a file with a 9GB hole
at the front.  This is not very helpful! So I'd like to know if
there's a way I can tell logrotate to only copy the actual data
in the file.

I think the correct answer is that the server process should do...
something... to ensure that its logfile can be handled in a reasonable
way by logrotate.  But what is that "something"?  (The logrotate
man page is of no help.)

Thanks,

-- JK


More information about the Ale mailing list