Message Board -  Archive

[ Login ] [ Create Account ]
[ Board List ] [ View Board ] [ Post Reply ]
  Author  Subject: Re: logrotate

Posted on 11-17-2003 06:39 p.m. ET  reply

Original Poster: Mark Krentel

> I saw Mark Krentel's recent article about logrotate and I have a
> question. I maintain a web server that occasionally has long-running
> CGIs (they can run for days). Occasionally, logrotate gets fired up and
> bounces apache in the postrotate clause. Bye bye CGI...

What do you mean by "bounce"? Normally, postrotate sends Apache a
HUP signal which will cause Apache to reinitialize itself, including
closing and reopening its log files. It's essential to send the HUP,
or else Apache will continue to write to the old file under the new

Are you saying that the HUP kills the CGI script? I've never thought
about it, but that really surprises me. I don't see why Apache would
kill its CGI processes when it gets a HUP. Are you sure that
postrotate merely sends a HUP and doesn't do something more
heavy-handed like stopping and restarting Apache?

> Is there a way to insert a prerotate script to detect the presence of a
> long-running CGI and then have that CGI abort the log rotation? I don't
> see any option for conditional execution in the (Redhat) logrotate
> documentation.

Not directly. You can write arbitrary shell code in the pre- and
postrotate scripts, but when prerotate finishes, the file wil get
rotated and then postrotate will run.

If you want to do a conditional rotation, that is, either rotate or
not depending on some external condition, then you should bypass
logrotate and do it directly from cron. Write a cron job that
evaluates the condition (maybe ps and grep in your case) and does a
forced rotation when appropriate.

But the real problem here is why Apache kills the CGI script in the
first place. I'm surprised that Apache would pass on a signal at all,
but even if it does, a HUP doesn't have to be fatal. Just catch the
signal in the CGI script and continue (with %SIG, if it's perl).


< Previous 1 Next >

Site Contents