commit:04dd40d98617a67de54f661482f2955acc4a1d52
author:Chip Black
committer:Chip Black
date:Mon Aug 18 02:08:27 2008 -0500
parents:fbac109aff440f2ecc8a4bc995ab2e2d3d4d675b
Added high-level check spawning daemon, removed .pl suffixes
diff --git a/runcheckdir b/runcheckdir
line changes: +98/-0
index 0000000..4964a4c
--- /dev/null
+++ b/runcheckdir
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+use File::Basename;
+use strict;
+
+
+my $dir = shift;
+unless (-d $dir) {
+	print "Arg is not a directory";
+	exit 1;
+}
+my $me = basename $dir;
+my ($status, $details);
+
+sub do_command {
+	my $command = shift;
+	$command =~ /^(\w+)(\s+(.*))?$/;
+	my ($do, $args) = ($1, $3);
+	if ($do eq 'mail') {
+		open MAIL, '|-', qq!mail -s "$me $status" $args! or die "Could not mail";
+		print MAIL $details,"\n";
+		close MAIL;
+	} elsif ($do eq 'exec') {
+		system($args);
+	} elsif ($do eq 'pipe') {
+		open PIPE, '|-', $args;
+		print PIPE "$status\n";
+		print PIPE $details;
+		close PIPE;
+	}
+}
+
+
+my ($checkcommand, %on);
+$on{success} = [];
+$on{failure} = [];
+$on{change} = [];
+
+open CONFIG, "$dir/check";
+while (<CONFIG>) {
+	my @words = split(/\s+/);
+	my $command = shift @words;
+	if ($command eq 'check') {
+		$checkcommand = join(' ', @words);
+	} elsif ($command eq 'on') {
+		my $when = shift @words;
+		if ($when eq 'failure') {
+			push @{$on{failure}}, join(' ', @words);
+		} elsif ($when eq 'success') {
+			push @{$on{success}}, join(' ', @words);
+		} elsif ($when eq 'change') {
+			push @{$on{change}}, join(' ', @words);
+		} else {
+			print "Unknown event in 'on', $dir/check line $.\n";
+		}
+	} else {
+		print "Unknown command '$command', $dir/check line $.\n";
+	}
+}
+close CONFIG;
+
+unless ($checkcommand) {
+	print "Check command not specified in $dir/check\n";
+	exit 1;
+}
+unless (@{$on{failure}} || @{$on{success}} || @{$on{change}}) {
+	print "No actions specified in $dir/check. This is probably a mistake.\n";
+}
+
+open STATUS, "$dir/checkstatus";
+chomp(my $oldstatus = <STATUS>);
+close STATUS;
+
+open CHECK, '-|', $checkcommand;
+$status = <CHECK>;
+$details = join('', <CHECK>);
+close CHECK;
+my $exitstatus = $? >> 8;
+
+if ($exitstatus == 0) {
+	foreach my $command (@{$on{success}}) {
+		do_command $command;
+	}
+} else {
+	foreach my $command (@{$on{failure}}) {
+		do_command $command;
+	}
+}
+if ($exitstatus != $oldstatus) {
+	foreach my $command(@{$on{change}}) {
+		do_command $command;
+	}
+}
+
+open STATUS, ">$dir/checkstatus";
+print STATUS "$exitstatus\n";
+print STATUS "$status\n";
+print STATUS "$details\n";
+close STATUS;

diff --git a/runcheckdir.pl b/runcheckdir.pl
line changes: +0/-98
index 4964a4c..0000000
--- a/runcheckdir.pl
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/perl
-use File::Basename;
-use strict;
-
-
-my $dir = shift;
-unless (-d $dir) {
-	print "Arg is not a directory";
-	exit 1;
-}
-my $me = basename $dir;
-my ($status, $details);
-
-sub do_command {
-	my $command = shift;
-	$command =~ /^(\w+)(\s+(.*))?$/;
-	my ($do, $args) = ($1, $3);
-	if ($do eq 'mail') {
-		open MAIL, '|-', qq!mail -s "$me $status" $args! or die "Could not mail";
-		print MAIL $details,"\n";
-		close MAIL;
-	} elsif ($do eq 'exec') {
-		system($args);
-	} elsif ($do eq 'pipe') {
-		open PIPE, '|-', $args;
-		print PIPE "$status\n";
-		print PIPE $details;
-		close PIPE;
-	}
-}
-
-
-my ($checkcommand, %on);
-$on{success} = [];
-$on{failure} = [];
-$on{change} = [];
-
-open CONFIG, "$dir/check";
-while (<CONFIG>) {
-	my @words = split(/\s+/);
-	my $command = shift @words;
-	if ($command eq 'check') {
-		$checkcommand = join(' ', @words);
-	} elsif ($command eq 'on') {
-		my $when = shift @words;
-		if ($when eq 'failure') {
-			push @{$on{failure}}, join(' ', @words);
-		} elsif ($when eq 'success') {
-			push @{$on{success}}, join(' ', @words);
-		} elsif ($when eq 'change') {
-			push @{$on{change}}, join(' ', @words);
-		} else {
-			print "Unknown event in 'on', $dir/check line $.\n";
-		}
-	} else {
-		print "Unknown command '$command', $dir/check line $.\n";
-	}
-}
-close CONFIG;
-
-unless ($checkcommand) {
-	print "Check command not specified in $dir/check\n";
-	exit 1;
-}
-unless (@{$on{failure}} || @{$on{success}} || @{$on{change}}) {
-	print "No actions specified in $dir/check. This is probably a mistake.\n";
-}
-
-open STATUS, "$dir/checkstatus";
-chomp(my $oldstatus = <STATUS>);
-close STATUS;
-
-open CHECK, '-|', $checkcommand;
-$status = <CHECK>;
-$details = join('', <CHECK>);
-close CHECK;
-my $exitstatus = $? >> 8;
-
-if ($exitstatus == 0) {
-	foreach my $command (@{$on{success}}) {
-		do_command $command;
-	}
-} else {
-	foreach my $command (@{$on{failure}}) {
-		do_command $command;
-	}
-}
-if ($exitstatus != $oldstatus) {
-	foreach my $command(@{$on{change}}) {
-		do_command $command;
-	}
-}
-
-open STATUS, ">$dir/checkstatus";
-print STATUS "$exitstatus\n";
-print STATUS "$status\n";
-print STATUS "$details\n";
-close STATUS;

diff --git a/runchecks b/runchecks
line changes: +31/-0
index 0000000..3467c28
--- /dev/null
+++ b/runchecks
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+use strict;
+
+my $dir = shift;
+unless (-d $dir) {
+	print "$dir is not a directory\n";
+	exit 1;
+}
+
+$|++;
+
+while (1) {
+	opendir(CHECKS, $dir);
+	while (my $d = readdir(CHECKS)) {
+		next if (! -d "$dir/$d" || $d eq '.' || $d eq '..');
+		unless (-f "$dir/$d/check") {
+			print "No check script in $dir/$d\n";
+			next;
+		}
+		print "Running check $dir/$d: ";
+		system("runcheckdir $dir/$d");
+		my $exitstatus = $? >> 8;
+		if ($exitstatus) {
+			print "FAILURE\n";
+		} else {
+			print "OK\n";
+		}
+		sleep 10;
+	}
+	closedir(CHECKS);
+}