Turns out there's a very simple way of handling log rotation - use the
'-0F' (large F instead of small f) tail switch and you don't need to
handle log rotation at all. Far too simple! Now grok will just run
and run ad infinitum, automatically detecting when files it's watching
have rotated. Thanks to Mel on this post from the freebsd-questions
mailing list:
http://groups.google.com/group/muc.lists.freebsd.questions/msg/102b062f0f2ffdfe
However there's still the issue of grok trapping external TERM/KILL
signals and the like so that any child procs it's spawned will be
dispatched with due diligence - would be good to have grok shut down
cleanly if it's in the background. This problem becomes less urgent
for me personally though now - with the use of the -0F switch I can
just leave grok running ad infinitum and not worry about restarting
grok every time a file is rotated.
Cheers.
--
Jez Hancock
- System Administrator / PHP Developer
http://freebsd.munk.me.uk/ - A FreeBSD Admin Weblog
http://ipfwstats.sf.net/ - ipfw peruser traffic logging
Good catch. Potentially the workaround for this (without hacking in
perl) woudl be to swap
file "foo" {. ....
with
exec "tail -0F foo" { ...
> http://groups.google.com/group/muc.lists.freebsd.questions/msg/102b062f0f2ffdfe
>
> However there's still the issue of grok trapping external TERM/KILL
> signals and the like so that any child procs it's spawned will be
> dispatched with due diligence - would be good to have grok shut down
> cleanly if it's in the background. This problem becomes less urgent
> for me personally though now - with the use of the -0F switch I can
> just leave grok running ad infinitum and not worry about restarting
> grok every time a file is rotated.
>
> Cheers.
>
I though the process death bug was fixed. I'll work on a patch.
-Jordan
I noticed the 'hack' and wasn't sure about it - left it well alone!
The only thing I feel is missing for me personally is the signal
handling. Mainly the two following signals:
KILL TERM (and other signals that are meant to reign death on processes!)
As above really, just to be able to send a signal ala 'kill -9 <pid>'
where <pid> is the grok 'parent' process.
Perhaps to facilitate this it might be worth having a '-p' switch so
you can state on the commandline where you want a pid file placing
which could contain the parent process id.
grok could then check for stale PID file first and if already running,
exit gracefully; otherwise continue to write the pid to the pidfile.
Having a pidfile would make it easier to send signals like:
KILL etc - to kill the process off and any child procs.
HUP - to have grok reread in it's configuration file
I'd just started on writing the PID file stuff, but realized quickly I
don't quite understand the reasons behind the hackinit method in the
'regexhack' package (I was wondering why on earth processes were
forking when I'd used exit liberally to debug... only to realize that
the regexhack::hackinit() call actually forks, hence the grok procs in
bg!).
So I did have a go... if it helps the pseudocode was like this (I
stopped coding when realized I didn't understand the hackinit code!):
if (exists($opts->{"b"})) {
# First check if we want to write to PID file:
if (exists($opts->{"p"})) {
my $pidfile = $opts->{"p"};
# Check for stale PID file first:
if( defined($pidfile) && -f $pidfile ){
open(PID, "< $pidfile") or die("Could not open $pidfile.\n");
my $pid = <PID>;
close PID;
chomp $pid;
# Send a CHLD sig to $pid. If PID is active running proc, return is 1;
# otherwise return is 0:
my $status = kill("SIGTERM", $pid);
if($status == 1){
# die gracefully, explain already running:
} elsif($status == 0) {
# Not already running, stale PID file, unlink:
}
}
# Continue to write PID file with parent pid $$:
}
I'll add a patch file anyway just in case.
Apart from the signal handling grok's been working very nicely on this
server for the last week or so now - basically using it to detect
trackback spam, brute force auth attacks, http XSS abuse and so on and
add offending IPs to respective pf tables.
Seems to be making a difference - I think blocking the hosts
completely makes a difference, before I was just blocking HTTP access
if a zombie attacked trackback comments, but since blocking them
outright on any port I've noticed a lot of DNS requests denied to
those IPs so hopefully perhaps they'll report back to their botnet
master that my host is dead (well I live in hope anyway :- ).
Once again, many thanks.
Will attach patch file now (FWIW!)