Commit 92fa4ae2 authored by Mac Newbold's avatar Mac Newbold

A few changes to stated:

 - fix bad indenting to a uniform 4 spaces (before was 2, 4 and 8 mixed)
 - Move ping-for-isup functionality into a separate script
 - Make sure every transition triggered by stated (directly or indirectly)
   sends an event, instead of taking shortcuts.

This called for a new script, eventping, which just pings until the node
is pingable, then sends an ISUP event. Stated runs this in the background
where necessary, and nothing else should run it.

Adding eventping meant modifying configure and the utils makefile, too.
parent 3eb650c8
......@@ -1352,7 +1352,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tmcd/tmcd.restart \
utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \
utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \
utils/firstuser utils/export_tables \
utils/firstuser utils/export_tables utils\eventping \
utils/cvsupd.pl \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
vis/GNUmakefile vis/webvistopology \
......
......@@ -395,7 +395,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tmcd/tmcd.restart \
utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \
utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \
utils/firstuser utils/export_tables \
utils/firstuser utils/export_tables utils\eventping \
utils/cvsupd.pl \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
vis/GNUmakefile vis/webvistopology \
......
This diff is collapsed.
......@@ -13,7 +13,8 @@ UNIFIED = @UNIFIED_BOSS_AND_OPS@
include $(OBJDIR)/Makeconf
BIN_SCRIPTS = delay_config sshtb create_image node_admin
SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl
SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
eventping
LIBEXEC_SCRIPTS = webcreateimage
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
# eventping - ping a node until it is reachable, then send ISUP event
# Configure variables
use lib '@prefix@/lib';
my $TB = "@prefix@";
my $BOSSNODE = "@BOSSNODE@";
my $TBOPS = "@TBOPSEMAIL@";
$| = 1;
use event;
use libdb; # event constants
use libtestbed; # sendmail
sub usage {
fatal("Usage: eventping <node>\n".
"Ping node until reachable, then send ISUP event.\n");
}
my $cmdline = "$0 ".join(" ",@ARGV);
if (@ARGV != 1) { usage(); }
my $d = 0;
my $node = shift;
my $maxtime=600; # Set the timer for 10 minutes
my $starttime = time();
my $endtime = $starttime + $maxtime;
while( time() <= $endtime ) {
my $status=system("/sbin/ping -c 1 -t 1 $node ".
"> /dev/null 2>&1 > /dev/null");
my $rv = $status >> 8;
my $sig = $status & 127;
debug("ping returned $status ($rv / $sig)\n");
if ($rv==0) {
# we got a response
EventSendFatal(host => $BOSSNODE ,
objtype => TBDB_TBEVENT_NODESTATE ,
eventtype => TBDB_NODESTATE_ISUP ,
objname => $node);
debug("Sent event ". TBDB_NODESTATE_ISUP ." for $node\n");
exit(0);
} elsif ($rv==2) {
# no response
} elsif ($rv==68) {
# ping: cannot resolve $node: Unknown host
fatal("eventping: cannot resolve $node: Unknown host\n");
} else {
# Unknown error
fatal("eventping: ping returned unknown error $rv ($sig)\n");
}
# sleep just a little bit so we can catch a ^C while debugging
if ($d) { select(undef,undef,undef,0.5); }
}
sub debug { if ($d) { print @_; } }
sub fatal ( $ ) {
my $msg = shift;
notify("FATAL: ".$msg);
die($msg);
}
sub notify ( $ ) {
my $msg = shift;
$msg .= "\ndate=".`date`."\ncmdline=\n$cmdline\n\npid=$$\n\n";
if (!$d) {
SENDMAIL($TBOPS,"eventping failure",$msg,$TBOPS);
} else {
debug("notify: Not sending mail in debug mode\n");
}
debug($msg);
}
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