I solved that problem with the attached perl script. A little kludgy,
but it works. I still haven't managed to figure out how to get Perl to
watch STDERR in addition to STDOUT, though.
It's not perfect, but it works well enough that I haven't been motivated
to improve it.
-Luke
On Thu, 2003-11-20 at 15:51, Redeeman wrote:
> a thing i could think of was a small script that checked if gpilot ran
> with ps aux and if it didnt, then start it, and run that script every
> minute via cron task
#!/usr/bin/perl
#
# NAME: gpilotd_babysitter
#
# PURPOSE: To watch gpilotd through pipes and kill it if something goes wrong.
#
# AUTHOR: Luke Scharf <[EMAIL PROTECTED]>, July 2003
#
use strict;
use warnings;
# Run gpilotd over and over again...
while (1) {
# Kill gpilotd
system("killall gpilotd");
sleep(1);
# Spawn our gpilotd daemon
my $command = "gpilotd";
for(my $i = 0; $i le $#ARGV; $i++) {
$command .= (" " . $ARGV[$i]);
}
print "Starting: $command\n";
open(GPILOTD, "$command &|"); # How do I read both stdin and stderr here?
# Let it run and see what happens!
my $proceed = 1;
my $line;
while ($proceed and $line = <GPILOTD> ) {
chomp($line);
print "Read: \"$line\"\n";
if ( $line =~ /Unable to bind to pilot/
or $line =~ /Synchronization ended/
or $line =~ /gpilotd-WARNING/
) {
$proceed = 0;
}
}
# Ok, we're done with it.
system("killall gpilotd");
sleep(1);
close(GPILOTD); # If this doesn't get it, the next iteration of the loop will.
}
--
[EMAIL PROTECTED] mailing list