Commit b8ad48ee authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

New script to shutdown (and restart) the testbed. What this really

does is set nologins, and then wait for swapping to stop (which might
take a little while of course) and then kill off all the testbed
daemons. This is probably the thing to do before reboot boss, from now
on.
parent c3a2abbf
......@@ -25,7 +25,7 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
spewconlog opsdb_control newnode suchown archive_list \
wanodecheckin wanodecreate spewimage \
anonsendmail epmodeset fixexpinfo node_traffic \
dumpdescriptor subboss_tftpboot_sync
dumpdescriptor subboss_tftpboot_sync testbed-control
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2010 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
use Data::Dumper;
#
# Update DB.
#
sub usage()
{
print STDERR "Usage: testbed-control [-d] [-f] shutdown | boot\n";
exit(-1);
}
my $optlist = "df";
my $debug = 0;
my $force = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $SETSITEVAR = "$TB/sbin/setsitevar";
my $STARTUP = "/usr/local/etc/rc.d/3.testbed.sh";
# Protos
sub Fatal($);
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
use lib "@prefix@/lib";
use libdb;
use libtestbed;
#
# Parse command arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"f"})) {
$force = 1;
}
usage()
if (@ARGV != 1);
usage()
if (! ($ARGV[0] eq "boot" || $ARGV[0] eq "shutdown"));
#
# Must be root if actually doing this.
#
if ($UID) {
Fatal("This script must be run as root! Maybe use sudo?")
}
sub Restart()
{
print "Starting up testbed daemons.\n";
system("$STARTUP start");
if ($?) {
print "*** Could not restart testbed daemons.\n";
exit(1);
}
print "\n";
print "Turning on the web interface and allowing swaps\n";
if (system("$SETSITEVAR web/nologins -") ||
system("$SETSITEVAR web/message -")) {
print "*** Could not renable the web interface and swapping!\n";
exit(1);
}
}
if ($ARGV[0] eq "boot") {
Restart();
exit(0);
}
#
# Stop the testbed before doing the update.
#
print "** Putting the testbed to sleep ...\n";
print "-> Turning off the web interface and disallowing swaps.\n";
my $msg = "Testbed going offline; back in a little while";
$msg =~ s|\&|&|g;
$msg =~ s|\<|&lt;|g;
system("$SETSITEVAR","web/message", $msg);
if ($?) {
Fatal("Could not update web message");
}
system("$SETSITEVAR web/nologins 1");
if ($?) {
Fatal("Could not disable web logins and experiment swaps");
}
print "-> Waiting a few seconds for testbed to quiet down ...\n";
sleep(5);
print "-> Looking for experiments still in transition.\n";
#
# Look for any experiments in transition, and wait for them to stop.
# This could take an arbitrarily long time of course, but its the only
# safe way to do it. Don't worry about any experiments that are older
# then 24 hours though; they are likely stuck and not going anywhere.
#
while (1) {
my $query_result =
DBQueryWarn("select pid,eid,idx,state,expt_locked ".
" from experiments ".
"where expt_locked is not null and ".
" DATE_SUB(NOW(),INTERVAL 1 DAY) <= expt_locked");
if (!$query_result) {
Fatal("Error getting info from the DB. Stopping.");
}
last
if (!$query_result->numrows());
print "-> Experiments still in transition:\n";
while (my ($pid,$eid,$idx,$state,$expt_locked) =
$query_result->query_result()) {
print " $pid,$eid,$idx -- $state, $expt_locked\n";
}
print "-> Waiting 30 seconds before trying again. ^C is okay\n\n";
sleep(30);
}
print "** Testbed is quiet; stopping testbed daemons ... \n";
system("$STARTUP stop >/dev/null 2>&1");
if ($?) {
Fatal("Could not stop testbed daemons. Stopping. Best to reboot!");
}
print "** Testbed is stopped. Safe to power off or reboot\n";
exit(0);
sub Fatal($)
{
my ($msg) = @_;
die("*** $0:\n".
" $msg\n");
}
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