Commit a8257b4e authored by Leigh Stoller's avatar Leigh Stoller

Make the detailed logging independent of impotent mode, so that we can

write a detailed log of ExecQuiet to a log in /var/tmp during
installation. Good for debugging. Pass -l option to emulab-install or
to update-install.
parent 62f98ccf
......@@ -14,9 +14,10 @@ use Data::Dumper;
#
sub usage()
{
print STDERR "Usage: emulab-install [-c] [-i script] boss|ops|fs\n";
print STDERR "Usage: emulab-install [-c | -l] [-i script] boss|ops|fs\n";
print STDERR
"-c - Syntax check install scripts by loading them only\n" .
"-l - Generate a complete log file in /tmp. Defaults on\n" .
"-i <name> - Run (or check) just the one install script\n" .
"-b - Batch mode, do not ask for confirmation\n" .
"-s - Turn on makes. Huh?\n" .
......@@ -25,13 +26,14 @@ sub usage()
"-p <dir> - Set the package directory\n";
exit(-1);
}
my $optlist = "dsi:p:qcbP:F:w:nu";
my $optlist = "dsi:p:qcbP:F:w:nul";
my $debug = 0;
my $single = 0;
my $quiet = 0;
my $check = 0;
my $impotent = 0;
my $updatemode = 0;
my $logit = 1;
my $batchmode = 0;
my $phasepath = "@srcdir@/phases";
my $phase;
......@@ -93,6 +95,9 @@ if (defined($options{"d"})) {
if (defined($options{"b"})) {
$batchmode = 1;
}
if (defined($options{"l"})) {
$logit = 1;
}
if (defined($options{"c"})) {
$check = 1;
}
......@@ -164,9 +169,16 @@ if ($UID && !($check || $impotent)) {
if (! ($batchmode || $check || $impotent)) {
if ($updatemode) {
print STDERR
"WARNING: This script is ONLY intended to be run your $server node,\n".
"and only if you are updating the IP addresses/subnet and/or the\n",
"domain name of your installation. Continue? [y/N] ";
"WARNING: This script is ONLY intended to be run your $server node";
if ($single) {
print STDERR ".\n" . "Continue? [y/N] ";
}
else {
print STDERR
",\n".
"and only if you are updating the IP addresses/subnet and/or\n".
"domain name of your installation. Continue? [y/N] ";
}
}
else {
print STDERR
......@@ -177,12 +189,24 @@ if (! ($batchmode || $check || $impotent)) {
die "Aborted!\n" unless ($response =~ /^y/i);
}
if ($impotent) {
if (($impotent || $logit) && !$check) {
if (-e $logfile) {
system("/bin/mv -f $logfile ${logfile}.$$") == 0
or Fatal("Could not back up $logfile");
}
open(LOGFP, "> $logfile")
or Fatal("Could not open $logfile");
$logfp = *LOGFP;
SET_IMPOTENT_MODE($logfp);
if ($impotent) {
SET_IMPOTENT_MODE($logfp);
}
else {
SET_LOG_OUTPUT($logfp);
}
print "A more detailed log file is being written to $logfile\n";
sleep(2);
}
#
......@@ -199,7 +223,8 @@ elsif ($server eq "boss") {
'apache', 'boss/rcfiles', 'boss/rcconf', 'boss/syslog',
'boss/database', 'etchosts', 'resolvetest',
'exports', 'nfsmounts', 'boss/mibs', 'boss/crontab', 'sudoers',
'boss/ssh', 'boss/rndc', 'boss/loaderconf', 'boss/sysctlconf',
'boss/ssh', 'boss/hostkeys',
'boss/rndc', 'boss/loaderconf', 'boss/sysctlconf',
'boss/sslcerts', 'boss/mailman', 'boss/pubsub',
'boss/software',
#
......@@ -229,8 +254,9 @@ elsif ($server eq "ops") {
#
# In update mode, we want to run etchosts at the very end.
# Also allow running a single script in update mode.
#
if ($updatemode) {
if ($updatemode && !$single) {
push(@files, "boss/update-ipdomain")
if ($server eq $BOSS_SERVERNAME);
......@@ -315,6 +341,9 @@ if ($updatemode) {
exit(0);
}
exit(0)
if ($single);
#
# Stuff to do at the end.
#
......
......@@ -53,6 +53,7 @@ my $impotent = 0;
my $logfp;
sub SET_IMPOTENT_MODE($) { $impotent = 1; $logfp = $_[0]; };
sub IMPOTENT_MODE() { return $impotent; }
sub SET_LOG_OUTPUT($) { $logfp = $_[0]; };
#
# Some programs we may call
......@@ -113,11 +114,11 @@ sub Phase($$$) {
if ($firstSubPhase) {
print "\n";
printf $logfp "\n"
if ($impotent);
if (defined($logfp));
}
printf "%-50s", $descrstring;
printf $logfp "%-50s", $descrstring
if ($impotent);
if (defined($logfp));
#
# Clear these, as we don't want to see the outputs of previous phases
......@@ -142,6 +143,8 @@ sub Phase($$$) {
my $stop = 0;
if ($hasSubPhase) {
print "| " x ($depth -1) . "+-" . "--" x (24 - $depth) . "> ";
print $logfp "| " x ($depth -1) . "+-" . "--" x (24 - $depth) . "> "
if (defined($logfp));
}
#
......@@ -151,7 +154,7 @@ sub Phase($$$) {
(/^skip$/) && do {
print "[ Skipped ($libinstall::reason) ]\n";
print $logfp "[ Skipped ($libinstall::reason) ]\n"
if ($impotent && defined($logfp));
if (defined($logfp));
$$parentSkipped++;
$libinstall::phaseResults{$name} = $_;
last SWITCH;
......@@ -175,7 +178,7 @@ sub Phase($$$) {
(/^stop$/) && do {
print "[ Stopped ]\n";
print $logfp "[ Stopped ($libinstall::reason) ]\n"
if ($impotent && defined($logfp));
if (defined($logfp));
$$parentNonSkipped++;
$message = "$libinstall::reason";
if ($impotent) {
......@@ -203,18 +206,18 @@ sub Phase($$$) {
if ($hasSubPhase && $skipped && ($nonSkipped == 0)) {
print "[ Skipped ] ($stamp)\n";
print $logfp "[ Skipped ]\n"
if ($impotent && defined($logfp));
if (defined($logfp));
$libinstall::phaseResults{$name} = "skip";
$$parentSkipped++;
} else {
if ($impotent) {
if (defined($logfp)) {
print $logfp "[ $libinstall::reason ]\n";
if (defined($logfp)) {
print $logfp "[ Succeeded ]\n";
print $logfp
"> " . join("\n> ", @libinstall::loglines) . "\n"
if (@libinstall::loglines);
}
print $logfp
"> " . join("\n> ", @libinstall::loglines) . "\n"
if (@libinstall::loglines);
}
if ($impotent) {
print "[ $libinstall::reason ]\n";
}
else {
......@@ -231,6 +234,8 @@ sub Phase($$$) {
# the wrong value
#
print "[ ERROR ]\n";
print $logfp "[ ERROR ]\n"
if (defined($logfp));
$$parentNonSkipped++;
$message = "Internal error - Bad exception:\n$_";
$libinstall::phaseResults{$name} = "fail";
......@@ -247,11 +252,15 @@ sub Phase($$$) {
# If we decided that we need to stop, do that now
#
if ($stop) {
print "\n";
print "############################################################\n";
print "Installation stopped in phase $name. The reason is:\n";
print "$message\n";
print "############################################################\n";
my $message =
"\n" .
"############################################################\n" .
"Installation stopped in phase $name. The reason is:\n" .
"$message\n" .
"############################################################\n";
print $message;
print $logfp $message
if (defined($logfp));
exit -1;
}
......@@ -259,8 +268,11 @@ sub Phase($$$) {
# If we decided that we need to die, do that now
#
if ($die) {
print "\n##### Installation failed in phase $name:\n";
print "$message\n";
my $message =
"\n##### Installation failed in phase $name:\n" . "$message\n";
print $message;
print $logfp $message
if (defined($logfp));
PrintPhaseTrace();
PrintLastOutput();
print "Please send the above output to testbed-ops\@emulab.net\n";
......@@ -529,8 +541,11 @@ sub DoneIfMounted($)
sub AppendToFile($@) {
my ($filename, @lines) = @_;
if (defined($logfp)) {
print $logfp "Append to file: $filename\n";
print $logfp "@lines\n";
}
if ($impotent) {
PhaseLog(@lines);
PhaseWouldHave("append to $filename");
return undef;
}
......@@ -567,8 +582,11 @@ sub AppendToFileFatal($@) {
sub CreateFile($;@) {
my ($filename,@lines) = @_;
if (defined($logfp)) {
print $logfp "Create file: $filename\n";
print $logfp "@lines\n";
}
if ($impotent) {
PhaseLog(@lines);
PhaseWouldHave("create $filename");
return undef;
}
......@@ -623,6 +641,18 @@ sub ExecQuiet(@) {
my $exit_value = $? >> 8;
#
# Detailed logging.
#
if (defined($logfp)) {
print $logfp "\n";
print $logfp "Exec('$commandstr')\n";
if (@output) {
print $logfp "@output";
print $logfp "\n";
}
}
@libinstall::lastExecOutput = @output;
$libinstall::lastCommand = $commandstr;
......@@ -761,15 +791,21 @@ sub GetPackage($$) {
# Print out the phase stack that got us here
#
sub PrintPhaseTrace() {
print "-------------------- Phase Stack ----------------------------\n";
my $message =
"-------------------- Phase Stack ----------------------------\n";
my @tmpphase = @libinstall::phasestack;
my @tmpdescr = @libinstall::descrstack;
my ($phase, $descr);
while (@tmpdescr) {
($phase, $descr) = (pop @tmpphase, pop @tmpdescr);
printf "%-10s %-50s\n", $phase, $descr;
$message .= sprintf "%-10s %-50s\n", $phase, $descr;
}
print "--------------------------------------------------------------\n";
$message .=
"--------------------------------------------------------------\n";
print $message;
print $logfp $message
if (defined($logfp));
}
#
......@@ -779,17 +815,24 @@ sub PrintLastOutput() {
if (!$libinstall::lastCommand) {
return;
}
print "------------------------------------------ Last Command Output\n";
print "Command: $libinstall::lastCommand\n";
print @libinstall::lastExecOutput;
print "--------------------------------------------------------------\n";
my $message =
"------------------------------------------ Last Command Output\n" .
"Command: $libinstall::lastCommand\n" .
"@libinstall::lastExecOutput" .
"--------------------------------------------------------------\n";
print $message;
print $logfp $message
if (defined($logfp));
}
sub LastOutput() {
if (!$libinstall::lastCommand) {
return ();
}
return @libinstall::lastExecOutput;
return ("------------------------------------------ Last Command Output\n",
"Command: $libinstall::lastCommand\n",
@libinstall::lastExecOutput,
"--------------------------------------------------------------\n");
}
#
......
......@@ -14,10 +14,10 @@ use Data::Dumper;
#
sub usage()
{
print STDERR "Usage: update-install [-v | -n] [-s] [-f] [<version>]\n";
print STDERR "Usage: update-install [-v | -n | -l] [-s] [-f] [<version>]\n";
exit(-1);
}
my $optlist = "dsfvp:qa:cin";
my $optlist = "dsfvp:qa:cinl";
my $debug = 0;
my $force = 0;
my $single = 0;
......@@ -25,6 +25,7 @@ my $verify = 0;
my $quiet = 0;
my $check = 0;
my $impotent= 0;
my $logit = 0;
my $path = ".";
my $phase;
my $version;
......@@ -36,13 +37,13 @@ my $logfp;
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $logfile = "/var/tmp/install.$$";
my $logfile = "/var/tmp/update-install.log";
# Protos
sub Fatal($);
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
......@@ -99,6 +100,9 @@ if (defined($options{"i"}) || defined($options{"n"})) {
if (defined($options{"f"})) {
$force = 1;
}
if (defined($options{"l"})) {
$logit = 1;
}
if (defined($options{"v"})) {
$verify = 1;
}
......@@ -143,12 +147,24 @@ sub MarkForReboot($)
return 0;
}
if ($impotent) {
if ($impotent || $logit) {
if (-e $logfile) {
system("/bin/mv -f $logfile ${logfile}.$$") == 0
or Fatal("Could not back up $logfile");
}
open(LOGFP, "> $logfile")
or Fatal("Could not open $logfile");
$logfp = *LOGFP;
SET_IMPOTENT_MODE($logfp);
if ($impotent) {
SET_IMPOTENT_MODE($logfp);
}
else {
SET_LOG_OUTPUT($logfp);
}
print "A more detailed log file is being written to $logfile\n";
sleep(2);
}
#
......
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