#!/usr/bin/perl -w
##############################################################################
# $Id$
##############################################################################
# Loop, running the ECV checks for the load balancer.
#
# We use this script instead of cron so that we can fail it from one box
# to another along with the load balancer.
##############################################################################

use IPC::Open3;

my $PAUSE = 120;

open(PID, '>/var/run/ecv_loop.pid') || die;
print PID $$;
close(PID);

while (1)
{
	my $pid = open3(\*CMDIN, \*CMDOUT, 0,
		'/root/scripts/balance_ecv', '389');
	die "Fork failed: $!" if (! $pid);

	close(CMDIN);

	my @output;
	while(<CMDOUT>)
	{
		push(@output, $_);
	}
	close(CMDOUT);

	waitpid($pid, 0);

	if (@output)
	{
		open(MAIL, '| mail -s "ECV check output" root');
		print MAIL @output;
		close(MAIL);
	}

	sleep $PAUSE;
}

