-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>);
-my $oldtime = (stat(STATUS))[9];
-close STATUS;
-
-my $td = time() - $oldtime;
-if ($td < $every) {
- # Not time to recheck yet
- #print "Not rechecking; ", $every - $td, " seconds to go.\n";
- exit $oldstatus;
-}
-
-my ($pid, $hung, $exitstatus);
-$SIG{ALRM} = sub {
- kill 9, $pid;
- $hung = 1;
-};
-alarm 10;
-
-$pid = open CHECK, '-|', $checkcommand;
-$status = <CHECK>;
-$details = join('', <CHECK>);
-close CHECK;
-if ($hung) {
- $status = 'TIMEOUT';
- $details = 'Check did not complete within ten seconds';
- $exitstatus = -1;
-} else {
- $exitstatus = $? >> 8;
-}
-
-if ($exitstatus == 0 && $oldstatus != 0) {
- do_command($_) foreach @{$on{success}};
-}
-if ($exitstatus != 0 && $oldstatus == 0) {
- do_command($_) foreach @{$on{failure}};
-}
-if ($exitstatus != $oldstatus) {
- do_command($_) foreach @{$on{change}};
-}
-
-open STATUS, ">$dir/checkstatus";
-print STATUS "$exitstatus\n";
-print STATUS "$status\n";
-print STATUS "$details\n";
-close STATUS;
-
-exit $exitstatus;