Commit 469bfac7 authored by Leigh B Stoller's avatar Leigh B Stoller

Fix up exit handling, was failing to kill children.

parent 4cead7b8
...@@ -88,6 +88,17 @@ if (! $debug) { ...@@ -88,6 +88,17 @@ if (! $debug) {
} }
} }
#
# Setup a signal handler to kill children and exit.
#
sub handler()
{
print "Caught a TERM. Killing children and exiting\n";
Cleanup();
exit(0);
}
$SIG{TERM} = \&handler;
# #
# Delay at startup to allow ops time to boot. Hopefully this # Delay at startup to allow ops time to boot. Hopefully this
# will prevent too many false alarms at system startup time. # will prevent too many false alarms at system startup time.
...@@ -97,16 +108,6 @@ sleep(60) ...@@ -97,16 +108,6 @@ sleep(60)
my ($opswatcher,$bosswatcher,$psdwatcher,$deadpid); my ($opswatcher,$bosswatcher,$psdwatcher,$deadpid);
#
# Setup a signal handler to kill children and exit.
#
sub handler()
{
fatal("Caught a TERM. Killing children and exiting\n")
if ($debug);
}
$SIG{TERM} = \&handler;
while (1) { while (1) {
# #
# We look for up to three different pubsubd daemons. One on ops, the # We look for up to three different pubsubd daemons. One on ops, the
...@@ -258,18 +259,8 @@ sub notify($) ...@@ -258,18 +259,8 @@ sub notify($)
$TBOPS); $TBOPS);
} }
sub fatal($) sub Cleanup()
{ {
my ($msg) = @_;
#
# Send a message to the testbed list.
#
SENDMAIL($TBOPS,
"Event watchdog daemon died",
$msg,
$TBOPS);
if (defined($opswatcher)) { if (defined($opswatcher)) {
kill('TERM', $opswatcher); kill('TERM', $opswatcher);
} }
...@@ -281,7 +272,22 @@ sub fatal($) ...@@ -281,7 +272,22 @@ sub fatal($)
} }
MarkDaemonStopped("event_watchdog") MarkDaemonStopped("event_watchdog")
if (!$debug); if (!$debug);
}
sub fatal($)
{
my ($msg) = @_;
#
# Send a message to the testbed list.
#
SENDMAIL($TBOPS,
"Event watchdog daemon died",
$msg,
$TBOPS);
Cleanup();
die("*** $0:\n". die("*** $0:\n".
" $msg\n"); " $msg\n");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment