[ale] Cooperating with logrotate

Brandon Checketts brandon at brandonchecketts.com
Fri Nov 6 13:54:15 EST 2009


The process that is writing to the log needs to close and reopen the file
handle.  Most applications support sending a HUP signal to tell the process to
reload its configuration, reopen log files, etc.  If this is a custom program,
then you would likely have to add support for that.  The exact method for doing
so depends on the language.

Once you know how to get your application to reopen the log, then you would use
a postrotate script in the logrotate config to trigger that.  As an example, the
logrotate config for Apache does this:

    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript

Thanks,
Brandon Checketts

JK wrote:
> 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
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo



More information about the Ale mailing list