httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Reppucci <>
Subject Re: Cleaning log files
Date Wed, 13 Mar 2002 12:56:49 GMT

You are correct, my statement that the file is unlinked is wrong
(funny how many times after you post something to a public list you
find a glaring error in your statements, huh? 8^), but I maintain
that 'cat'ing /dev/null to an open log file is *not* something that
should be relied upon, as I know it causes failures on some Unix
flavors. (If I remember correctly, this did not work on Solaris

The 'mv' option *is* safe (safe == reliable), but the key point is
apache will continue to write to the 'mv'ed file until you tell it
to reopen its log files, thereby having it close the old file (which
now has a different name) and open a new log file with the original
name. Sending it a 'SIGUSR1' is the documented way of doing this.


On Wed, 13 Mar 2002, alex dyas wrote:

> 'cat /dev/null > log_file' does *not* unlink the file and does not cause
> the problems you've described (at least not under Solaris 2.7/2.8). I've
> been using this method for quite a while now quite sucessfully.
> The problems come when you try using mv to move the old apache log file
> away while apache is still running.  AFAIK apache's link to the log file
> is through its inode, not its name. Thus moving the file doesn't help.
> alex..
> Stephen Reppucci wrote:
> > Depends on how you define "safe", but I'd *not* use the method
> > you've illustrated here...
> >
> > Apache still has the original log file open, so even after doing the
> > 'cat', it'll still go along happily writing to the (now unlinked)
> > log file, and you'll lose those log records.  Depending upon whether
> > you're trying to preserve those logs (e.g., for traffic analysis)
> > this could be "a bad thing".  Regardless, the disk storage for the
> > logs won't be released until apache closes the log file.
> >
> > I've used logrotate before, but for a few large sites I maintained,
> > I was happier with a couple of custom shell scripts I hacked
> > together that (after 'grep'ing through the server configs to find
> > the log files) did the equivalent of:
> >
> >    mv access_log access_log.yyyyddmm.hhmmss
> >    apachectl graceful
> >
> > The 'graceful' sends a SIGUSR1 to the apache parent process, which
> > causes it to tell all of its children to close and reopen the log
> > file *after* completing any current transaction.  This technique has
> > always worked like a charm for me.
> >
> > Note that this is how it works under Unix, all bets are off as to
> > how the Win* OSes handle it...
> >
> > hth,
> > <Steve>
> >
> > On Wed, 13 Mar 2002, Dror Braznitzki wrote:
> >
> >
> >>Is it safe to clean log files using 'cat /dev/null > log_file' while the
> >>server is running ?
> >>Is there a better way of doing it ?
> >>
> >>Thanx,
> >>Dror
> >>

Steve Reppucci                              |
Logical Choice Software                 |
=-=-=-=-=-=-=-=-=-=-  My God!  What have I done?  -=-=-=-=-=-=-=-=-=-=

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message