Re: Logrotate is a pain

From: Jean-David Beyer (jdbeyer_at_exit109.com)
Date: 06/04/05


Date: Sat, 04 Jun 2005 15:48:33 -0400

Doug O'Leary wrote:
> On 2005-05-27, Fritz Bayer <fritz-bayer@web.de> wrote:
>
>>Can you tell me where I can find a better replacement? The most
>>important feature is that the program, which writes the logfiles does
>>not have to be restarted or reload or anything else. That nobody has
>>to touch it.
>
>
> As mentioned, your best option would be to write a logrotate script
> yourself. It's not difficult. The key aspect, that logrotate seems
> to have missed is that if you rename an open log file, the processes
> writing to it continues writing to it regardless of the name. The reason
> is that the process is writing to an open inode; it really doesn't care
> what the file's name is.
>
> The proper way to do this is to copy the file to another location. Then,
> when the copy is complete and the return code is checked, simply truncate
> the log file.
>
> For instance:
>
> Date=$(date +"%y%m%d")
> cp /var/log/httpd/access_log /var/log/httpd/access_log.${Date}
> [[ $? -eq 0 ]] && > /var/log/httpd/access_log
>
> That way the inode doesn't change and the process continues writing
> to the original log file.
>
Why make your life so difficult? Use logrotate as it is meant to be used.
You can simply put a simple line in it to send SIGHUP to your daemon and the
daemon, if properly written, will close its logfile and re-open it. Here is
the entry for the syslog daemon and some of its friends:

[/etc/logrotate.d]$ cat syslog
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler
/var/log/boot.log /var/log/cron {
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null
|| true
    endscript
}

-- 
  .~.  Jean-David Beyer          Registered Linux User 85642.
  /V\  PGP-Key: 9A2FC99A         Registered Machine   241939.
 /( )\ Shrewsbury, New Jersey    http://counter.li.org
 ^^-^^ 15:40:00 up 6 days, 22:15, 5 users, load average: 5.45, 5.12, 4.60


Relevant Pages

  • Re: Too many open files - why is this?
    ... > I'm developing an application (Tcl 8.4/AIX) which writes to a number of ... > logfiles. ... > What I like to do when writing to a log file is: ... There is only ever one log file open at a ...
    (comp.lang.tcl)
  • Too many open files - why is this?
    ... I'm developing an application (Tcl 8.4/AIX) which writes to a number of ... logfiles. ... What I like to do when writing to a log file is: ...
    (comp.lang.tcl)
  • Re: Multi-Threading
    ... 100,000+ line log file and decided to use multi-threading as a solution to ... Multi-threading on the desktop is useful when you're executing long running ... getting the info is a problem or is writing it the database, ... Do Until intcount> intcount1 ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Set Trace to Ignore Errors in Trace.WriteLine?
    ... opened and locked - other processes should not be able to lock ... The problem appears to be something reading the log file not writing to it. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Hard Drive Space
    ... of the distribution, ... security problems it had over the life of the distribution. ... in the space, either the box is 0wn3d, or you have a process that is writing ... If you don't recall removing some log file manually, ...
    (linux.redhat)