Commit 6cde8593 authored by Leigh B Stoller's avatar Leigh B Stoller

Utility script to run sliveraction on a local sliver.

parent 84023ab2
......@@ -36,7 +36,8 @@ PGENISUPPORT = @PROTOGENI_SUPPORT@
include $(OBJDIR)/Makeconf
SBIN_STUFF = cleanupslice gencabundle cleanupticket aptssh-setup
SBIN_STUFF = cleanupslice gencabundle cleanupticket aptssh-setup \
sliveraction
PSBIN_STUFF = register_resources expire_daemon gencrl postcrl \
addauthority getcacerts \
......@@ -55,7 +56,8 @@ endif
# These scripts installed setuid, with sudo.
SETUID_BIN_SCRIPTS =
SETUID_SBIN_SCRIPTS = cleanupslice gencabundle cleanupticket aptssh-setup
SETUID_SBIN_SCRIPTS = cleanupslice gencabundle cleanupticket aptssh-setup \
sliveraction
SETUID_LIBX_SCRIPTS =
#
......
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2014 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
# GENI Public License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
#
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
#
# Cleanup a dead slice on the machine running a CM.
#
sub usage()
{
print "Usage: sliveraction [-f] start|stop|restart <urn>\n";
exit(1);
}
sub fatal($);
my $optlist = "f";
my $force = 0;
my $locked = 0;
my $childpid = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
# 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;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use GeniDB;
use GeniSlice;
use GeniUtil;
use GeniCM;
use GeniCertificate;
use GeniCredential;
use GeniAggregate;
#
# We don't want to run this script unless its the real version.
#
if ($EUID != 0) {
die("*** $0:\n".
" Must be root! Maybe its a development version?\n");
}
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"f"})) {
$force = 1;
}
usage()
if (@ARGV != 2);
my $action = $ARGV[0];
my $token = $ARGV[1];
# Connect to the proper DB.
DBConnect(GENICM_DBNAME());
#
# Need an RPC context for this to work.
#
my $certificate = GeniCertificate->LoadFromFile("$TB/etc/genicm.pem");
fatal("Could not load CM certificate")
if (!defined($certificate));
Genixmlrpc->SetContext(Genixmlrpc->Context($certificate));
$ENV{'MYUUID'} = $certificate->uuid();
$ENV{'MYURN'} = "urn:publicid:IDN+@OURDOMAIN@+authority+cm";
my $slice = GeniSlice->Lookup($token);
if (!defined($token)) {
fatal("No such slice for $token");
}
if ($slice->Lock()) {
fatal("Could not lock slice $slice")
if (!$force);
}
else {
$locked = 1;
}
my $aggregate = GeniAggregate->SliceAggregate($slice);
if (!defined($aggregate)) {
fatal("No local aggregate for $slice");
}
GeniUtil::FlipToGeniUser();
if ($action eq "start") {
$aggregate->Start(2, 0) == 0
or fatal("Could not start $aggregate");
}
elsif ($action eq "stop") {
$aggregate->Stop(2) == 0
or fatal("Could not stop $aggregate");
}
elsif ($action eq "restart") {
$aggregate->Start(2, 1) == 0
or fatal("Could not restart $aggregate");
}
#
# See if we forked, If so, we wait.
#
if ($childpid) {
waitpid($childpid, 0);
if ($?) {
fatal("Failed to $action $slice");
}
}
$slice->UnLock()
if ($locked);
exit(0);
sub WrapperFork()
{
# Need this in the child.
my $parent_lockname = "lock_$PID";
# Before the fork, lock the lock in the parent. It will be
# unlocked just before the parent exits, this informing the
# child.
emdb::DBQueryWarn("select GET_LOCK('$parent_lockname', 5)");
$childpid = fork();
if ($childpid) {
# Tell caller we are the parent,
return $childpid;
}
# XXX Need to let the parent finish up first, but the parent is
# is in the "defunct" state, so cannot use kill(0) to figure out
# it is gone.
emdb::DBQueryWarn("select GET_LOCK('$parent_lockname', 15)");
return 0;
}
sub fatal($) {
my ($msg) = @_;
print STDERR "$msg\n";
$slice->UnLock()
if ($locked);
exit(1);
}
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