Commit 42266abf authored by Mac Newbold's avatar Mac Newbold
Browse files

Add logging to @prefix@/log/power.log - writes down when and how it was...

Add logging to @prefix@/log/power.log - writes down when and how it was rebooted. Will aid in some debugging tasks, and will be much more important after merging the new stated stuff, when node_reboot will check the state of the node before rebooting it.
parent fbadd74c
...@@ -40,10 +40,12 @@ my $TB = "@prefix@"; ...@@ -40,10 +40,12 @@ my $TB = "@prefix@";
use lib "@prefix@/lib"; use lib "@prefix@/lib";
use libdb; use libdb;
use libtestbed; use libtestbed;
use POSIX qw(strftime);
my $ssh = "$TB/bin/sshtb -n"; my $ssh = "$TB/bin/sshtb -n";
my $power = "$TB/bin/power"; my $power = "$TB/bin/power";
my $ipod = "$TB/sbin/ipod"; my $ipod = "$TB/sbin/ipod";
my $logfile = "$TB/log/power.log";
my $ping = "/sbin/ping"; my $ping = "/sbin/ping";
my %pids = (); my %pids = ();
my @row; my @row;
...@@ -166,7 +168,7 @@ foreach my $node ( @nodes ) { ...@@ -166,7 +168,7 @@ foreach my $node ( @nodes ) {
} }
@nodes = @temp; @nodes = @temp;
if (! @nodes) { if (! @nodes) {
print "No nodes to load. Exiting ...\n"; print "No nodes to reboot. Exiting ...\n";
exit(0); exit(0);
} }
...@@ -208,6 +210,7 @@ while (@sortednodes) { ...@@ -208,6 +210,7 @@ while (@sortednodes) {
# In force mode, call the power program for the whole batch, and # In force mode, call the power program for the whole batch, and
# continue on. We don't wait for them to go down or reboot. # continue on. We don't wait for them to go down or reboot.
# #
info("Force mode: power cycle ".join(" ",@batch));
system("$power cycle @batch"); system("$power cycle @batch");
if ($?) { if ($?) {
exit ($? >> 8); exit ($? >> 8);
...@@ -290,6 +293,7 @@ sub RebootNode { ...@@ -290,6 +293,7 @@ sub RebootNode {
# ping returns 0 if any packets make it through. # ping returns 0 if any packets make it through.
# #
if (! DoesPing($pc)) { if (! DoesPing($pc)) {
info("$pc appears dead: power cycle");
print STDERR "$pc appears to be dead. Power cycling ...\n" if $debug; print STDERR "$pc appears to be dead. Power cycling ...\n" if $debug;
if (PowerCycle($pc)) { if (PowerCycle($pc)) {
exit(-1); exit(-1);
...@@ -340,9 +344,12 @@ sub RebootNode { ...@@ -340,9 +344,12 @@ sub RebootNode {
} else { } else {
print STDERR "$pc is wedged.\n" if $debug; print STDERR "$pc is wedged.\n" if $debug;
} }
info("$pc: ssh reboot failed ... sending ipod");
print STDERR "Trying Ping-of-Death on $pc ...\n" if $debug; print STDERR "Trying Ping-of-Death on $pc ...\n" if $debug;
system("$ipod $pc"); system("$ipod $pc");
} else {
info("$pc: ssh reboot");
} }
} }
else { else {
...@@ -367,8 +374,10 @@ sub RebootNode { ...@@ -367,8 +374,10 @@ sub RebootNode {
exit(0); exit(0);
} }
info("$pc: ipod failed ... power cycle");
print STDERR "$pc is still running. Power cycling ...\n" if $debug; print STDERR "$pc is still running. Power cycling ...\n" if $debug;
if (PowerCycle($pc)) { if (PowerCycle($pc)) {
info("$pc: power cycle failed!");
exit(-1); exit(-1);
} }
exit(0); exit(0);
...@@ -433,3 +442,12 @@ sub DoesPing { ...@@ -433,3 +442,12 @@ sub DoesPing {
} }
return 1; return 1;
} }
sub info($) {
my $message = shift;
# Print out log entries like this:
# Sep 20 09:36:00 $message
open(LOG,">> $logfile");
print LOG strftime("%b %e %H:%M:%S",localtime)." $message\n";
close(LOG);
}
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