Commit 0c8ccb1d authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

A bunch of little changes to the client startup scripts, including

bringing the sharks up to date.
parent 62341a85
......@@ -29,6 +29,7 @@ install:
$(INSTALL) -m 755 $(SRCDIR)/setup $(INSTALL_DIR)/setup
$(INSTALL) -m 755 $(SRCDIR)/rc.testbed $(INSTALL_DIR)/rc.testbed
$(INSTALL) -m 755 $(SRCDIR)/rc.setup $(INSTALL_DIR)/rc.setup
$(INSTALL) -m 755 $(SRCDIR)/runstartupcmd $(INSTALL_DIR)/runstartupcmd
$(INSTALL) -m 644 $(SRCDIR)/hosts $(INSTALL_DIR)/hosts
$(INSTALL) -m 755 ../tmcc $(INSTALL_DIR)/tmcc
$(INSTALL) -m 755 $(SRCDIR)/supfile $(INSTALL_DIR)/supfile
......
......@@ -20,8 +20,9 @@ if [ -x /etc/testbed/rc.rpm ]; then
/etc/testbed/rc.rpm
fi
if [ -x /etc/testbed/startupcmd ]; then
/bin/rm -f /var/at/jobs/S*
if [ -s /etc/testbed/startupcmd ]; then
echo "Scheduling startup command to run in a little bit ..."
/bin/rm -f /var/at/jobs/S*
echo "/etc/testbed/runstartup" | at -q S 'now + 5 minutes'
echo "/etc/testbed/runstartup" | at -q S 'now + 2 minutes'
fi
......@@ -23,6 +23,8 @@ my $DELAYCMD = "delay";
my $HOSTSCMD = "hostnames";
my $RPMCMD = "rpms";
my $STARTUPCMD = "startupcmd";
my $STARTSTATCMD= "startstatus";
my $READYCMD = "ready";
my $IFCONFIG = "/sbin/ifconfig fxp%d inet %s netmask %s ".
"media 100baseTX mediaopt full-duplex\n";
my $RPMINSTALL = "/usr/local/bin/rpm -i %s\n";
......@@ -235,8 +237,14 @@ if (@delays) {
$count++;
}
print DEL "echo \"Delay Configuration Complete\"\n";
#
# If a delay node, then lets report status and ready in so that batch
# experiments do not become stuck.
#
print DEL "$TMCC $READYCMD\n";
print DEL "$TMCC $STARTSTATCMD 0\n";
print DEL "echo \"Delay Configuration Complete\"\n";
close(DEL);
chmod(0755, "$TMDELAY");
......
......@@ -30,6 +30,7 @@ install:
$(INSTALL) -m 600 $(SRCDIR)/gshadow $(INSTALL_DIR)/gshadow
$(INSTALL) -m 755 $(SRCDIR)/rc.testbed $(INSTALL_DIR)/rc.testbed
$(INSTALL) -m 755 $(SRCDIR)/rc.setup $(INSTALL_DIR)/rc.setup
$(INSTALL) -m 755 $(SRCDIR)/runstartupcmd $(INSTALL_DIR)/runstartupcmd
$(INSTALL) -m 755 $(SRCDIR)/setup $(INSTALL_DIR)/setup
$(INSTALL) -m 644 $(SRCDIR)/hosts $(INSTALL_DIR)/hosts
$(INSTALL) -m 755 ../tmcc $(INSTALL_DIR)/tmcc
......
......@@ -15,8 +15,8 @@ if [ -x /etc/rc.d/testbed/rc.rpm ]; then
/etc/rc.d/testbed/rc.rpm
fi
if [ -x /etc/rc.d/testbed/startupcmd ]; then
/bin/rm -f /var/spool/at/S*
if [ -s /etc/rc.d/testbed/startupcmd ]; then
echo "Scheduling startup command to run in a little bit ..."
/bin/rm -f /var/spool/at/S*
echo "/etc/rc.d/testbed/runstartup" | at -q S 'now + 5 minutes'
echo "/etc/rc.d/testbed/runstartup" | at -q S 'now + 2 minutes'
fi
......@@ -26,4 +26,6 @@ install:
$(INSTALL) -m 600 $(SRCDIR)/master.passwd $(INSTALL_DIR)/master.passwd
$(INSTALL) -m 755 $(SRCDIR)/setup $(INSTALL_DIR)/setup
$(INSTALL) -m 755 $(SRCDIR)/rc.testbed $(INSTALL_DIR)/rc.testbed
$(INSTALL) -m 755 $(SRCDIR)/runstartupcmd $(INSTALL_DIR)/runstartupcmd
$(INSTALL) -m 644 $(SRCDIR)/hosts $(INSTALL_DIR)/hosts
$(INSTALL) -m 755 ../tmcc $(INSTALL_DIR)/tmcc
......@@ -9,3 +9,9 @@ if [ -x /etc/testbed/rc.ifc ]; then
echo "Setting up Testbed interfaces..."
/etc/testbed/rc.ifc
fi
/bin/rm -f /var/at/jobs/S*
if [ -s /etc/testbed/startupcmd ]; then
echo "Scheduling startup command to run in a little bit ..."
echo "/etc/testbed/runstartup" | at -q S 'now + 2 minutes'
fi
#!/usr/pkg/bin/perl -wT
use English;
#
# We are run out of the at daemon as root.
#
my $TMCC = "/etc/testbed/tmcc";
my $TMNICKNAME = "/etc/testbed/nickname";
my $TMSTARTUPCMD = "/etc/testbed/startupcmd";
#$TMRUNCMD = "/tmp/startupcmd";
#
# Untaint path
#
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/local/bin:/etc/testbed';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Disconnect from the caller (at daemon).
#
if (background()) {
#
# Parent exits normally
#
exit 0;
}
#
# Open up the command file, which tells us what to do.
#
open(CMD, "$TMSTARTUPCMD") or
fatal("Could not open $TMSTARTUPCMD: $!");
my $runcmd;
my $login;
while (<CMD>) {
if ($_ =~ /CMD=\'([-\@\w.\/ ]+)\' UID=([0-9a-z]+)/) {
$runcmd = $1;
$login = $2;
}
}
if (!defined($runcmd) || !defined($login)) {
fatal("$TMSTARTUPCMD not in proper format!");
}
(undef,undef,$uid,$gid,undef,undef,undef,$homedir) = getpwnam($login) or
fatal("Could not determine UID for $login");
#
# Fork a child so that we can run the command as the user and wait for it.
#
$mypid = fork();
if ($mypid) {
#
# Parent waits for child.
#
waitpid($mypid, 0);
$stat = $?;
}
else {
#
# The child becomes the user and runs the command.
#
$EGID = $GID = $gid;
$EUID = $UID = $uid;
exec($runcmd);
fatal("Could not exec $runcmd");
}
print STDOUT "$runcmd returned $stat\n";
#
# Use the TMCC to tell the TMCD what the exit status was.
#
system("$TMCC startstatus $stat");
#
# Put the log file in the callers home dir! Hmm, what about name clashes?
#
(undef,undef,undef,undef,undef,undef,undef,$homedir) = getpwnam($login);
system("/bin/cp", "$logname", "$homedir");
exit(0);
sub fatal($)
{
my($mesg) = $_[0];
print STDOUT "$mesg\n";
#
# Use the TMCC to tell the TMCD that we screwed the pooch.
#
system("$TMCC startstatus 666");
exit(-1);
}
#
# Put ourselves into the background so that caller sees immediate response.
#
sub background()
{
# Turn off line buffering on output
#
$| = 1;
$mypid = fork();
if ($mypid) {
return $mypid;
}
#
# Open up the nickname file so we can generate a meaningfull filename.
#
$nickname = `hostname -s`;
if (open(NICK, "$TMNICKNAME")) {
$nickname = <NICK>;
close(NICK);
}
# Taint check (strips newline too)
if ($nickname =~ /^([-\@\w.]+)$/) {
$nickname = $1;
} else {
die "Bad data in $nickname";
}
#
# We have to disconnect from the caller by redirecting both STDIN and
# STDOUT away from the pipe. Otherwise the caller (the web server) will
# continue to wait even though the parent has exited.
#
open(STDIN, "< /dev/null") or
die("opening /dev/null for STDIN: $!");
#
# Create a temporary name for a log file and untaint it.
#
$logname = `mktemp /var/tmp/runlog-$nickname.XXXXXX`;
# Note different taint check (allow /).
if ($logname =~ /^([-\@\w.\/]+)$/) {
$logname = $1;
} else {
die "Bad data in $logname";
}
open(STDERR, ">> $logname") or die("opening $logname for STDERR: $!");
open(STDOUT, ">> $logname") or die("opening $logname for STDOUT: $!");
return 0;
}
......@@ -6,16 +6,21 @@ use English;
#
my $TMCC = "/etc/testbed/tmcc";
my $TMIFC = "/etc/testbed/rc.ifc";
my $TMRPM = "/etc/testbed/rc.rpm";
my $TMSTARTUPCMD= "/etc/testbed/startupcmd";
my $TMGROUP = "/etc/testbed/group";
my $TMPASSWD = "/etc/testbed/master.passwd";
my $TMHOSTS = "/etc/testbed/hosts";
my $HOSTSFILE = "/etc/hosts";
my @CONFIGS = ($TMIFC);
my $TMNICKNAME = "/etc/testbed/nickname";
my @CONFIGS = ($TMIFC, $TMRPM, $TMSTARTUPCMD, $TMNICKNAME);
my $REBOOTCMD = "reboot";
my $STATCMD = "status";
my $IFCCMD = "ifconfig";
my $ACCTCMD = "accounts";
my $HOSTSCMD = "hostnames";
my $RPMCMD = "rpms";
my $STARTUPCMD = "startupcmd";
my $IFCONFIG = "/sbin/ifconfig cs%d alias %s netmask %s ".
"media 10baseT mediaopt full-duplex\n";
my $CP = "/bin/cp -f";
......@@ -27,6 +32,8 @@ my $IFACE = "cs";
my $CTLIFACENUM = "0";
my $CTLIFACE = "${IFACE}${CTLIFACENUM}";
my $project = "";
my $eid = "";
my $vname = "";
my $PROJDIR = "/proj";
my $MOUNTCMD = "/sbin/mount fs.emulab.net:/q/proj/";
my $HOSTNAME = "%s\t%s-%s %s\n";
......@@ -71,14 +78,25 @@ if ($_ =~ /^FREE/) {
print STDOUT " Free!\n";
exit(0);
}
if ($_ =~ /ALLOCATED=([-\@\w.]*)\/([-\@\w.]*)/) {
print STDOUT " Allocated: $1/$2!\n";
if ($_ =~ /ALLOCATED=([-\@\w.]*)\/([-\@\w.]*) NICKNAME=([-\@\w.]*)/) {
$project = $1;
$eid = $2;
$vname = $3;
$nickname= "$vname.$eid.$project";
print STDOUT " Allocated! PID: $1, EID: $2, NickName: $nickname\n";
}
else {
die("Error getting reservation status\n");
}
#
# Stick our nickname in a file in case someone wants it.
#
open(NICK, ">$TMNICKNAME")
or die("Could not open $TMNICKNAME");
print NICK "$nickname\n";
close(NICK);
#
# Mount the project directory.
#
......@@ -217,6 +235,26 @@ while (<TM>) {
}
close(TM);
#
# Experiment startup Command.
#
print STDOUT "Checking Testbed Experiment Run Command configuration ... \n";
open(TM, "$TMCC $NODE $STARTUPCMD |")
or die "Cannot start $TMCC: $!";
$_ = <TM>;
close(TM);
if ($_ =~ /CMD=(\'[-\@\w.\/ ]+\') UID=([0-9a-z]+)/) {
open(RUN, ">$TMSTARTUPCMD")
or die("Could not open $TMSTARTUPCMD");
print STDOUT " Will run $1 as $2\n";
print RUN "$_\n";
close(RUN);
chmod(0755, "$TMSTARTUPCMD");
}
#
# If node is free, reset to a moderately clean state.
#
......
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