Commit 51bc0de4 authored by Leigh Stoller's avatar Leigh Stoller

A bunch of logfile changes. Logs are now saved in the experiment

directory so that they can be viewed later after the operation is
complete. I've also cleaned up the mechanism for determining when
a log file is active (for the web spew) by using another slot in the
experiments table, and added some libdb routines to manage that slot.
At present just the last (or latest) log can be viewed after the fact,
but we can change that later if think its really necessary. At the
same time, make it possible for admin types to view the log files for
other peoples expierments; spew is setuid, but flips back after
opening the file (does usual checks too). I've also incorporated the
log changes into the batch daemon, so you can view the last batch log
too, although I have not tested that yet!
parent dfd200a6
......@@ -35,6 +35,7 @@ my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $logname;
my $isopen;
#
# Load the Testbed support stuff.
......@@ -78,7 +79,16 @@ if ($eid =~ /^([-\@\w]+)$/) {
}
else {
die("*** Bad data in eid: $eid\n");
}
}
#
# This script is setuid, so please do not run it as root. Hard to track
# what has happened.
#
if ($UID == 0) {
die("*** $0:\n".
" Please do not run this as root! Its already setuid!\n");
}
#
# Verify that this person is allowed to do this.
......@@ -91,7 +101,7 @@ if (!TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_READINFO)) {
#
# Get the logfile name.
#
if (! TBExptGetLogFile($pid, $eid, \$logname)) {
if (! TBExptGetLogFile($pid, $eid, \$logname, \$isopen)) {
die("*** $0:\n".
" There is no logfile to view for $pid/$eid!\n");
}
......@@ -100,14 +110,28 @@ use Fcntl;
use IO::Handle;
STDOUT->autoflush(1);
#
# If not an admin type, flip back to the UID now to enforce normal
# permissions.
#
if (! TBAdmin($UID)) {
$EUID = $UID;
}
sysopen(LOG, $logname, O_RDONLY | O_NONBLOCK) or
die("*** $0:\n".
" Could not open $logname. Must no longer be in transition!");
" Could not open $logname: $!\n");
#
# If an admin type, flip back to the UID now that the file is open.
#
if (TBAdmin($UID)) {
$EUID = $UID;
}
#
# Loop reading the file in nonblocking mode. Sleep between loops, and
# check for a change in status. For now, this is simply accomplished
# by checking to make sure the name of the logfile has not changed!
# check for a change in status.
#
while (1) {
my $tmp;
......@@ -115,7 +139,8 @@ while (1) {
while (sysread(LOG, $buf, 2048)) {
print STDOUT "$buf";
}
if (! TBExptGetLogFile($pid, $eid, \$tmp) || $tmp ne $logname) {
if (! TBExptGetLogFile($pid, $eid, \$tmp, \$isopen) || !$isopen ||
$tmp ne $logname) {
last;
}
sleep(2);
......
......@@ -95,6 +95,13 @@ my $nsfile= $ARGV[2];
if (defined($options{"b"})) {
$batch = 1;
$logname = $options{"b"};
if ($logname =~ /^([-\@\w.\/]+)$/) {
$logname = $1;
}
else {
die("Bad data in logfile name: $logname");
}
}
if (defined($options{"f"})) {
$frontend = 1;
......@@ -140,13 +147,7 @@ else {
}
if (!defined($logname)) {
$logname = `mktemp /tmp/start-$pid-$eid.XXXXXX`;
}
if ($logname =~ /^([-\@\w.\/]+)$/) {
$logname = $1;
}
else {
die("Bad data in logfile name: $logname");
$logname = TBExptCreateLogFile($pid, $eid, "start");
}
my $repfile = "$eid.report";
......@@ -222,6 +223,7 @@ TBLockExp($pid, $eid);
#
if (! $batch) {
TBExptSetLogFile($pid, $eid, $logname);
TBExptOpenLogFile($pid, $eid);
if (TBBackGround($logname)) {
#
......@@ -361,7 +363,15 @@ SENDMAIL("$user_name <$user_email>",
"Bcc: $TBLOGS",
($repfile, $logname, $nsfile));
TBExptClearLogFile($pid, $eid);
#
# Move the temporary log file into the experiment directory and change the
# name in the DB. This makes it available to the web interface later on
# if desired.
#
system("cp -pf $logname $expt_path/tbdata/startexp.log");
TBExptCloseLogFile($pid, $eid);
TBExptSetLogFile($pid, $eid, "$expt_path/tbdata/startexp.log");
unlink($logname);
exit 0;
......@@ -383,8 +393,6 @@ sub fatal()
# In batch mode, exit.
#
if ($batch) {
TBExptClearLogFile($pid, $eid);
TBUnLockExp($pid, $eid);
exit($errorstat);
}
......@@ -410,6 +418,12 @@ sub fatal()
DBQueryWarn("DELETE from experiments ".
"WHERE eid='$eid' and pid='$pid'");
#
# Move the temporary log file into the experiment directory so its kept.
#
system("cp -pf $logname $expt_path/tbdata/startexp.log");
TBExptClearLogFile($pid, $eid);
#
# Save a copy of the failed experiment directory for debugging.
......@@ -421,7 +435,6 @@ sub fatal()
system("/bin/mv", "-f", "${expt_path}", "${expt_path}-TBfailed");
}
TBExptClearLogFile($pid, $eid);
unlink($logname);
exit($errorstat);
}
......
......@@ -30,6 +30,7 @@ my $TB = "@prefix@";
my $DBNAME = "@TBDBNAME@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $TBINFO = "$TB/expinfo";
#
# Testbed Support libraries
......@@ -236,15 +237,9 @@ if (! UserDBInfo($expt_head_login, \$expt_head_name, \$expt_head_email)) {
# If not in batch mode, go into the background. Parent exits.
#
if (! $batch) {
$logname = `mktemp /tmp/swap-$pid-$eid.XXXXXX`;
if ($logname =~ /^([-\@\w.\/]+)$/) {
$logname = $1;
}
else {
die("Bad data in logfile name: $logname");
}
$logname = TBExptCreateLogFile($pid, $eid, "end");
TBExptSetLogFile($pid, $eid, $logname);
TBExptOpenLogFile($pid, $eid);
if (TBBackGround($logname)) {
#
......@@ -291,6 +286,23 @@ else {
}
system("$tbdir/tbreport -b $pid $eid 2>&1 > $repfile");
#
# Try to copy off the files for testbed information gathering.
#
my $infodir = "$pid-$eid-" . TBDateTimeFSSafe();
if (mkdir("$TBINFO/$infodir", 0770)) {
system("cp $logname $TBINFO/$infodir/$eid.log");
if (-e "assign.log") {
system("cp *.ptop *.top $TBINFO/$infodir");
system("cp assign.log $TBINFO/$infodir");
}
if (-e "wanassign.log") {
system("cp wanassign.log $TBINFO/$infodir");
}
}
}
#
......@@ -324,8 +336,15 @@ SENDMAIL("$user_name <$user_email>",
"Bcc: $TBLOGS",
($repfile, $logname));
TBExptClearLogFile($pid, $eid);
if (defined($logname)) {
#
# Move the temporary log file into the experiment directory and
# change the name in the DB. This makes it available to the web
# interface later on if desired.
#
system("cp -pf $logname $expt_path/tbdata/swapexp.log");
TBExptCloseLogFile($pid, $eid);
TBExptSetLogFile($pid, $eid, "$expt_path/tbdata/swapexp.log");
unlink("$logname");
}
exit 0;
......@@ -346,7 +365,6 @@ sub fatal($)
# In batch mode, exit without sending the email.
#
if ($batch) {
TBExptClearLogFile($pid, $eid);
TBUnLockExp($pid, $eid);
exit(-1);
}
......@@ -362,8 +380,15 @@ sub fatal($)
"Cc: $TBOPS",
($logname));
TBExptClearLogFile($pid, $eid);
if (defined($logname)) {
#
# Move the temporary log file into the experiment directory and
# change the name in the DB. This makes it available to the web
# interface later on if desired.
#
system("cp -pf $logname $expt_path/tbdata/swapexp.log");
TBExptCloseLogFile($pid, $eid);
TBExptSetLogFile($pid, $eid, "$expt_path/tbdata/swapexp.log");
unlink("$logname");
}
exit(-1);
......
......@@ -55,6 +55,7 @@ if (! TBExptLogFile($pid, $eid)) {
}
header("Content-Type: text/plain");
ignore_user_abort(0);
$retval = 0;
$result = system("$TBSUEXEC_PATH $uid $pid spewlogfile $pid $eid", $retval);
......
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