Commit 33c9eafc authored by Leigh Stoller's avatar Leigh Stoller

Utility script to shutdown the shared node pool, as for shutting

down the entire testbed.
parent e277960d
......@@ -53,7 +53,7 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
prereserve_check tcppd addexternalnetwork \
update_sitevars delete_image sitecheckin sitecheckin_client \
mktestbedtest fixrootcert addservers poolmonitor \
node_exclude managetaint
node_exclude managetaint shutdown-shared
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage webdumpdescriptor \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2010-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
use Data::Dumper;
#
# Update DB.
#
sub usage()
{
print STDERR "Usage: shutdown-shared [-n] [node ...]\n";
exit(-1);
}
my $optlist = "n";
my $impotent = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $SSHTB = "$TB/bin/sshtb -n";
my $CLIENT_BIN = "@CLIENT_BINDIR@";
# 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;
use libEmulab;
use Experiment;
#
# Parse command arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"n"})) {
$impotent = 1;
}
#
# Must be root if actually doing this.
#
if ($UID) {
Fatal("This script must be run as root! Maybe use sudo?")
}
#
# Grab the shared node experiment. Multiple shared pools?
#
my $experiment =
Experiment->Lookup(TBOPSPID(), "shared-nodes") ||
Experiment->Lookup(TBOPSPID(), "shared-node");
if (!defined($experiment)) {
Fatal("Could not lookup shared node experiment. Exiting ...");
}
my @nodelist = $experiment->NodeList();
#
# We want to do this in parallel.
#
my $coderef = sub {
my ($node) = @_;
my $node_id = $node->node_id();
#
# Must change our real UID to root so that ssh will work.
#
$UID = 0;
if ($impotent) {
print "Would shut down containers on $node ...\n";
system("$SSHTB -host $node_id lvs");
}
else {
print "Shutting down containers on $node ...\n";
system("$SSHTB -host $node_id $CLIENT_BIN/bootvnodes -f -h");
}
return 1
if ($?);
return 0;
};
# Return codes for each node.
my @results = ();
if (ParRun({"maxwaittime" => 99999, "maxchildren" => 5},
\@results, $coderef, @nodelist)) {
Fatal("ParRun failed!");
}
#
# Check the exit codes.
#
my $count = 0;
my $failed = 0;
foreach my $result (@results) {
my ($node) = $nodelist[$count];
my $node_id = $node->node_id();
if ($result) {
print STDERR "Shutdown failed on $node_id\n";
}
$count++;
}
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