Commit c662a71b authored by Kevin Atkinson's avatar Kevin Atkinson

Fix up write-vis-auth-boss so that it 1) uses TBScriptLock to keep

more than one instance from running at once and 2) can run in the
background by mailing testbed-ops on error.
parent 2bbbc940
......@@ -5,12 +5,8 @@
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
#
# ...
#
use File::Temp;
#
# Configure variables
......@@ -19,12 +15,7 @@ my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $USERNODE = "@USERNODE@";
#
# Load the Testbed support stuff.
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
my $background = 0;
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
......@@ -33,13 +24,53 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# Turn off line buffering on output
$| = 1;
#
# Capture stdout and stderr to a file so if we die we can mail the output to
# testbed-ops
#
# XXX: Don't hardcode
my $logfile = "/tmp/write-vis-auth.$$";
use vars qw(*OLDOUT *OLDERR);
open OLDOUT, ">&STDOUT" or die "Can't dup STDOUT $!";
open OLDERR, ">&STDERR" or die "Can't dup STDERR $!";
open STDOUT, ">$logfile" or die "Can't open $logfile: $!";
open STDERR, ">&STDOUT" or die "Can't dup STDERR $!";
$SIG{__DIE__} = sub {
return unless defined $^S; # In Parser
return if $^S; # In Eval Block
local $_ = $_[0];
open STDOUT, ">&OLDOUT";
open STDERR, ">&OLDERR";
SENDMAIL($TBOPS, "write-vis-auth failed", $_, undef, undef, $logfile);
unlink $logfile;
print STDERR "write-vis-auth failed, see testbed-ops mail\n";
exit(1);
};
#
# Load the Testbed support stuff.
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
if ((my $locked = TBScriptLock("write-vis-auth", 1)) != TBSCRIPTLOCK_OKAY()) {
exit(0)
if ($locked == TBSCRIPTLOCK_IGNORE);
die("Could not get the lock after a long time!\n");
}
# become root, needed for ssh
$< = $>;
my $db_result =
DBQueryFatal("select opskey, uid from login");
open O, "| ssh root\@$USERNODE $TB/libexec/write-vis-auth-ops";
open O, "| ssh root\@$USERNODE $TB/libexec/write-vis-auth-ops"
or die "ssh to ops failed: $!\n";
my $prev_opskey = '';
while (my ($opskey,$uid) = $db_result->fetchrow_array) {
......@@ -48,4 +79,9 @@ while (my ($opskey,$uid) = $db_result->fetchrow_array) {
close O;
die "ssh to ops failed: $!\n" if $!;
die "ssh to ops failed with exit code $?\n" if $? != 0;
unlink $logfile;
exit(0);
......@@ -1066,7 +1066,7 @@ function DOLOGIN_MAGIC($uid, $uid_idx, $email = null, $adminon = 0)
# Proj-vis cookies
setcookie("exp_vis_session", $opskey, 0, "/", $TBAUTHDOMAIN, 0);
exec("$TBLIBEXEC_DIR/write-vis-auth-boss");
exec("$TBLIBEXEC_DIR/write-vis-auth-boss > /dev/null 2>&1 &");
return 0;
}
......@@ -1178,7 +1178,8 @@ function DOLOGOUT($user) {
}
#
exec("$TBLIBEXEC_DIR/write-vis-auth-boss");
setcookie("exp_vis_session", "", $timeout, "/", $TBAUTHDOMAIN, 0);
exec("$TBLIBEXEC_DIR/write-vis-auth-boss > /dev/null 2>&1 &");
return 0;
}
......
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