logrotate problem - Help
This is a discussion on logrotate problem - Help ; Hi,
I seem to be having a problem with logrotate, or not understanding the
way logrotate works.
I have a log that is created from a redirection in a script ( ... >
mylog.log)
The thing is, that when this ...
-
logrotate problem
Hi,
I seem to be having a problem with logrotate, or not understanding the
way logrotate works.
I have a log that is created from a redirection in a script ( ... >
mylog.log)
The thing is, that when this log gets rotated, the wrong file keeps
growing. Something like this:
0 nov 3 17:24 mylog.log
422 nov 3 17:43 mylog.log.1
Instead of mylog.log growing, now mylog.log.1 grows. And tomorrow, I
will have 2 zero size files, and mylog.log.2 will grow.
Is there any way to make this work without having to restart my
process?
Thank you,
- Brian
-
Re: logrotate problem
On Tue, 04 Nov 2003 03:59:03 +1100, Brian wrote:
> Hi,
>
> I seem to be having a problem with logrotate, or not understanding the
> way logrotate works.
>
> I have a log that is created from a redirection in a script ( ... >
> mylog.log)
>
> The thing is, that when this log gets rotated, the wrong file keeps
> growing. Something like this:
>
> 0 nov 3 17:24 mylog.log
> 422 nov 3 17:43 mylog.log.1
>
> Instead of mylog.log growing, now mylog.log.1 grows. And tomorrow, I
> will have 2 zero size files, and mylog.log.2 will grow.
>
> Is there any way to make this work without having to restart my
> process?
>
> Thank you,
> - Brian
Put a SIGHUP handler and generate a PID file in the script. On the HUP
close and reopen the logfile. Tell logrotate in postrotate processing to
"kill -HUP `cat /the/PIF/file`" the script.
--
Avoid reality at all costs.
$email =~ s/oz$/au/o;
-
Re: logrotate problem
> Put a SIGHUP handler and generate a PID file in the script. On the HUP
> close and reopen the logfile. Tell logrotate in postrotate processing to
> "kill -HUP `cat /the/PIF/file`" the script.
I don't really know how to do this, although now I know what to
investigate, thank you very much. :-)
You mean that this won't actually restart my process?
- Brian
-
Re: logrotate problem
On Wed, 05 Nov 2003 06:52:54 +1100, Brian wrote:
>> Put a SIGHUP handler and generate a PID file in the script. On the HUP
>> close and reopen the logfile. Tell logrotate in postrotate processing to
>> "kill -HUP `cat /the/PIF/file`" the script.
>
> I don't really know how to do this, although now I know what to
> investigate, thank you very much. :-)
>
> You mean that this won't actually restart my process?
Not if you get the SIGHUP handler right. do 'info bash' and search for
`trap' (exactly as typed).
try this:
somewhere that gets executed once
trap 'SIGED=1' SIGHUP
then in your main processing loop
if [ $SIGED -eq 1 ] ; then
SIGED=0
close the logfile
open the logfile
fi
--
Avoid reality at all costs.
$email =~ s/oz$/au/o;
-
Re: logrotate problem

Originally Posted by
Brian
I seem to be having a problem with logrotate, or not understanding the
way logrotate works. I have a log that is created from a redirection in a script ( ... > mylog.log) The thing is, that when this log gets rotated, the wrong file keeps
growing. Something like this:
0 nov 3 17:24 mylog.log
422 nov 3 17:43 mylog.log.1
Instead of mylog.log growing, now mylog.log.1 grows. And tomorrow, I
will have 2 zero size files, and mylog.log.2 will grow.
Here is my understanding of what is happening: logrotate seems like its doing an "mv" on mylog.log to mylog.log.1 but your program is just continuing to write its output, but now to a file named mylog.log.1. What is needed is for the logging to continue, but to to mylog.log. To do this, your program doing the logging needs to close its current log output file (which is now mylog.log.1) and (re)open mylog.log and write its output to mylog.log. If your program was created to accept the HUP signal, then upon receipt of that signal, it should close its log file and reopen it, then this should fix the problem - thats what the "kill -HUP pid" stuff is about and that's what programs are supposed to do with a HUP (in addition to rereading config files). I'm referring to a C program here (and you have referred to your shell script) because I was trying to figure the same thing out, but for a C program.