Commit 5df263b8 authored by Mike Hibler's avatar Mike Hibler
Browse files

Merge remote branch 'central/master'

parents 4f581537 4ac00cef
......@@ -80,7 +80,6 @@ boss-install: $(addprefix $(INSTALL_BINDIR)/, $(BIN_SCRIPTS)) \
$(addprefix $(INSTALL_DIR)/opsdir/lib/, $(USERLIBS))
post-install:
chown root $(INSTALL_SBINDIR)/subboss_dhcpd_makeconf
chown root $(INSTALL_SBINDIR)/genelists
chmod u+s $(INSTALL_SBINDIR)/genelists
chown root $(INSTALL_SBINDIR)/dhcpd_makeconf
......
......@@ -592,6 +592,46 @@ sub IsReserved($)
return 1;
}
sub GetSubboss($$)
{
my ($self, $service, $subboss_id) = @_;
return 0
if (! ref($self));
my $ref;
if (defined $self->{"SUBBOSSES"}) {
my $ref = $self->{"SUBBOSSES"}->{$service};
}
if (!defined $ref) {
my $nodeid = $self->node_id();
my $query_result =
DBQueryWarn("select * from subbosses " .
"where node_id='$nodeid' and " .
"service = '$service'");
return 0
if (!$query_result);
return 0
if (!$query_result->numrows);
if (!defined($self->{"SUBBOSSES"})) {
$self->{"SUBBOSSES"} = {};
}
$ref = $self->{"SUBBOSSES"}->{$service} =
$query_result->fetchrow_hashref();
}
$$subboss_id = $ref->{'subboss_id'};
return 0;
}
#
# Flush the reserve info so it reloads.
#
......
......@@ -8,17 +8,22 @@ SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = protogeni/scripts
ISMAINSITE = @TBMAINSITE@
include $(OBJDIR)/Makeconf
SBIN_STUFF = cleanupslice
PSBIN_STUFF = register_resources expire_daemon gencrl postcrl \
createcerts initsite addauthority getcacerts \
initsite addauthority getcacerts \
gencrlbundle shutdownslice remauthority listusage \
update reregister cleanupticket listhistory \
register_sliver sa_daemon genadmincredential \
genclrcredentials genallow_extcred
ifeq ($(ISMAINSITE),1)
SBIN_STUFF += ch_daemon
endif
# These scripts installed setuid, with sudo.
SETUID_BIN_SCRIPTS =
SETUID_SBIN_SCRIPTS = cleanupslice
......
#!/usr/bin/perl -w
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
#
# Look for things that need to be expired and resources released. This is
# incredibly primitive at the moment.
#
sub usage()
{
print "Usage: ch_daemon [-d] [-n]\n";
exit(1);
}
my $optlist = "dn";
my $debug = 0;
my $impotent = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $PGENIDOMAIN = "@PROTOGENI_DOMAIN@";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $PGENICLRHOUSE = @PROTOGENI_CLEARINGHOUSE@;
my $LOGFILE = "$TB/log/ch_daemon.log";
my $EMULAB_PEMFILE = "$TB/etc/genich.pem";
my $SLEEP_INTERVAL = 60;
my $PROBE_INTERVAL = (60 * 60 * 24);
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# Protos
sub fatal($);
sub notify($);
#
# Probe interval countdown. Set to zero so it runs right away.
#
my $probe_countdown = 0;
#
# Turn off line buffering on output
#
$| = 1;
if ($UID != 0) {
fatal("Must be root to run this script\n");
}
#
# Exit if not a protogeni site.
#
if (! $PGENISUPPORT) {
exit(0);
}
#
# Check args early so we get the right DB.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"n"})) {
$impotent = 1;
}
# Do this early so that we talk to the right DB.
use vars qw($GENI_DBNAME);
$GENI_DBNAME = "geni-ch";
# Load the Testbed support stuff.
use lib "@prefix@/lib";
require GeniDB;
require GeniUtil;
require GeniCertificate;
require GeniAuthority;
require libGeni;
use libtestbed;
use emutil;
use POSIX qw(strftime ceil);
#
# So we know who/what we are acting as.
#
my $certificate = GeniCertificate->LoadFromFile($EMULAB_PEMFILE);
if (!defined($certificate)) {
fatal("Could not get uuid/urn from $EMULAB_PEMFILE\n");
}
Genixmlrpc->SetContext(Genixmlrpc->Context($certificate));
Genixmlrpc->SetTimeout(10);
$ENV{'MYUUID'} = $certificate->uuid();
$ENV{'MYURN'} = "urn:publicid:IDN+@OURDOMAIN@+authority+ch";
if (CheckDaemonRunning("ch_daemon")) {
fatal("Not starting another ch daemon!");
}
# Go to ground.
if (! $debug) {
if (TBBackGround($LOGFILE)) {
exit(0);
}
}
if (MarkDaemonRunning("ch_daemon")) {
fatal("Could not mark daemon as running!");
}
#
# Setup a signal handler for newsyslog.
#
sub handler()
{
my $SAVEEUID = $EUID;
$EUID = 0;
ReOpenLog($LOGFILE);
$EUID = $SAVEEUID;
}
$SIG{HUP} = \&handler
if (!$debug);
GeniUtil::FlipToGeniUser();
# Do not wait long.
Genixmlrpc->SetTimeout(10);
#
# Probe CMs
#
sub ProbeCMs()
{
my @authorities = ();
my $up = "Up:\n";
my $down = "Down:\n";
my $disabled = "Disabled:\n";
if (GeniAuthority->ListAll(\@authorities)) {
fatal("Could not get authorities list from the DB");
}
foreach my $authority (@authorities) {
my $urn = $authority->urn();
next
if ($authority->type() ne "cm");
if ($authority->disabled()) {
$disabled .= "$urn\n";
next;
}
print "Contacting $urn\n";
my $version = $authority->Version();
if (!defined($version)) {
print "Error getting version from $urn\n";
$down .= "$urn\n";
}
else {
print " Running version $version\n";
$up .= "$urn, version $version\n";
}
}
SENDMAIL("geni-dev-utah\@flux.utah.edu",
"ClearingHouse Daemon Message",
"This is an automated message from the ClearingHouse Daemon\n\n".
$up . "\n" . $down . "\n" . $disabled . "\n", $TBOPS);
}
while (1) {
next
if (NoLogins());
print "Running at ".
POSIX::strftime("20%y-%m-%d %H:%M:%S", localtime()) . "\n";
$probe_countdown -= $SLEEP_INTERVAL;
if ($probe_countdown <= 0) {
ProbeCMs();
$probe_countdown = $PROBE_INTERVAL;
}
# Be certain stale info is gone.
GeniUtil::FlushCaches();
sleep($SLEEP_INTERVAL);
}
exit(0);
sub fatal($)
{
my ($msg) = @_;
#
# Send a message to the testbed list.
#
SENDMAIL($TBOPS,
"ProtoGENI CH daemon died",
$msg,
$TBOPS);
MarkDaemonStopped("ch_daemon");
die("*** $0:\n".
" $msg\n");
}
sub notify($)
{
my ($msg) = @_;
print "$msg\n";
SENDMAIL($TBOPS, "ClearingHouse Daemon Message", $msg, $TBOPS);
}
......@@ -81,6 +81,11 @@ case "$1" in
@prefix@/sbin/protogeni/sa_daemon
fi
if [ -x @prefix@/sbin/protogeni/ch_daemon ]; then
echo -n " ch_daemon"
@prefix@/sbin/protogeni/ch_daemon
fi
if [ -x @prefix@/sbin/checknodes_daemon ]; then
echo -n " checknodes_daemon"
@prefix@/sbin/checknodes_daemon
......@@ -144,6 +149,9 @@ case "$1" in
if [ -r /var/run/sa_daemon.pid ]; then
kill `cat /var/run/sa_daemon.pid`
fi
if [ -r /var/run/ch_daemon.pid ]; then
kill `cat /var/run/ch_daemon.pid`
fi
if [ -r /var/run/checknodes.pid ]; then
kill `cat /var/run/checknodes.pid`
fi
......
......@@ -43,7 +43,7 @@ SBIN_STUFF = resetvlans console_setup.proxy sched_reload named_setup \
elabinelab snmpit.proxy panic node_attributes \
nfstrace plabinelab smbpasswd_setup smbpasswd_setup.proxy \
rmproj snmpit.proxynew snmpit.proxyv2 pool_daemon \
checknodes_daemon
checknodes_daemon subboss_frisbeelauncher_wrapper
ifeq ($(ISMAINSITE),1)
SBIN_STUFF += repos_daemon
endif
......@@ -95,7 +95,7 @@ SETUID_BIN_SCRIPTS = node_reboot eventsys_control tarfiles_setup savelogs \
SETUID_SBIN_SCRIPTS = mkproj rmgroup mkgroup frisbeelauncher frisbeeimage \
rmuser idleswap named_setup exports_setup \
sfskey_update setgroups newnode_reboot vnode_setup \
elabinelab nfstrace rmproj
elabinelab nfstrace rmproj subboss_frisbeelauncher_wrapper
SETUID_LIBX_SCRIPTS = console_setup spewlogfile
ifeq ($(SYSTEM),FreeBSD)
......@@ -231,6 +231,8 @@ endif
chmod u+s $(INSTALL_SBINDIR)/mkgroup
chown root $(INSTALL_SBINDIR)/frisbeelauncher
chmod u+s $(INSTALL_SBINDIR)/frisbeelauncher
chown root $(INSTALL_SBINDIR)/subboss_frisbeelauncher_wrapper
chmod u+s $(INSTALL_SBINDIR)/subboss_frisbeelauncher_wrapper
chown root $(INSTALL_SBINDIR)/frisbeeimage
chmod u+s $(INSTALL_SBINDIR)/frisbeeimage
chown root $(INSTALL_SBINDIR)/rmuser
......
......@@ -45,6 +45,7 @@ my $PROJROOT = "@PROJROOT_DIR@";
my $MAXRETRIES = 1;
my $FRISBEELAUNCHER = "$TB/sbin/frisbeelauncher";
my $SUBBOSS_FRISBEELAUNCHER = "$TB/sbin/subboss_frisbeelauncher_wrapper";
my $osselect = "$TB/bin/os_select";
my $TBUISP = "$TB/bin/tbuisp";
......@@ -452,6 +453,7 @@ sub osload ($$) {
my $class = $nodeobject->class();
my $isremote = $nodeobject->isremotenode();
my $isvirtnode = $nodeobject->isvirtnode();
my $subboss;
my $reload_mode;
my $reload_func;
my $reboot_required;
......@@ -465,6 +467,7 @@ sub osload ($$) {
$reload_mode = "Frisbee";
$reload_func = \&SetupReloadFrisbee;
$reboot_required = !$noreboot; # Reboot unless $noreboot flag set
$nodeobject->GetSubboss('frisbee', \$subboss);
if (defined($nodeflags{$node})
&& defined($nodeflags{$node}{'noreboot'})) {
......@@ -506,6 +509,7 @@ sub osload ($$) {
'zerofree' => $zerofree,
'prepare' => $prepare,
'maxwait' => $maxwait,
'subboss' => $subboss,
'isremote' => $isremote,
'isvirtnode' => $isvirtnode
};
......@@ -981,6 +985,7 @@ sub SetupReloadFrisbee($)
my $zerofree = $reload_info->{'zerofree'};
my $prepare = $reload_info->{'prepare'};
my $isvirtnode = $reload_info->{'isvirtnode'};
my $subboss = $reload_info->{'subboss'};
my $osid = TBNodeDiskloadOSID($node);
#
......@@ -1016,6 +1021,25 @@ sub SetupReloadFrisbee($)
}
foreach my $imageid (@$imageids) {
if (defined $subboss) {
my $image = Image->Lookup($imageid);
my $filename = $image->filename();
my @image_stats = stat $filename;
my $query_result = DBQueryWarn("select sync from subboss_images where " .
"subboss_id = '$subboss' and imageid = '$imageid' and sync = 1");
if (!$query_result || !$query_result->numrows) {
system("$SUBBOSS_FRISBEELAUNCHER " . ($debug ? "-d ": "") .
"$subboss " . "$imageid " . "\"$filename\" " .
stat[7] . ' ' . stat[9]);
if ($?) {
tberror "Subboss Frisbee Launcher ($imageid on $subboss) failed!";
return -1;
}
return 0;
}
}
system("$FRISBEELAUNCHER " . ($debug ? "-d ": "") . "$imageid");
if ($?) {
tberror "Frisbee Launcher ($imageid) failed!";
......
......@@ -843,12 +843,13 @@ sub RebootVNode($$) {
exit(GeniEmulab->StartSlivers($experiment, [ $nodeobj ]));
}
my $addargs = "";
my $addargs = "-t "; # Turn on timestamps.
if ($plab) {
$addargs .= "-p ";
}
elsif ($jailed) {
$addargs .= "-j ";
# Use virtual control net routes.
$addargs .= "-jV ";
}
else {
$addargs .= "-i ";
......
......@@ -15,17 +15,19 @@ use Data::Dumper;
#
sub usage()
{
print STDOUT "Usage: pool_daemon [-d]\n" .
print STDOUT "Usage: pool_daemon [-d] [nsfile]\n" .
"Use the -d option to prevent daemonization\n";
exit(-1);
}
my $optlist = "dne";
my $optlist = "dne1";
my $debug = 0;
my $impotent = 0;
my $killme = 0;
my $nofree = 1;
my $gotlock = 0;
my $mailsent = 0;
my $oneshot = 0;
my $nsfile;
#
# Configure variables
......@@ -35,6 +37,7 @@ my $TBOPS = "@TBOPSEMAIL@";
my $BOSSNODE = "@BOSSNODE@";
my $logfile = "$TB/log/poollog";
my $SWAPEXP = "$TB/bin/swapexp";
my $tmpfile = "/tmp/pool-$$.nsfile";
# Testbed Support library
use lib "@prefix@/lib";
......@@ -87,29 +90,35 @@ my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV != 0) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"1"})) {
$oneshot = 1;
}
if (defined($options{"n"})) {
$impotent = 1;
}
if (defined($options{"e"})) {
$nofree = 1;
}
usage()
if (@ARGV > 1);
$nsfile = $ARGV[0]
if (@ARGV == 1);
$oneshot = 1
if (defined($nsfile));
if (!$impotent && CheckDaemonRunning("pool_daemon")) {
fatal("Not starting another pool daemon!");
}
# Go to ground.
if (! ($debug || $impotent)) {
if (! ($oneshot || $debug || $impotent)) {
if (TBBackGround($logfile)) {
exit(0);
}
}
if (!$impotent && MarkDaemonRunning("pool_daemon")) {
if (!($impotent || $oneshot) && MarkDaemonRunning("pool_daemon")) {
fatal("Could not mark daemon as running!");
}
#
......@@ -120,7 +129,7 @@ sub handler()
ReOpenLog($logfile);
}
$SIG{HUP} = \&handler
if (!($debug || $impotent));
if (!($oneshot || $debug || $impotent));
print "Pool Daemon starting... pid $$, at ".`date`;
......@@ -226,6 +235,12 @@ while (!$killme) {
print "Skipping this loop cause the experiment is swapped\n";
goto loop;
}
if (defined($nsfile)) {
print "Copying $nsfile to $tmpfile\n";
system("/bin/cp -f $nsfile $tmpfile") == 0
or fatal("Could not copy nsfile");
goto skipns;
}
my @nodelist = $experiment->NodeList();
my %inuse = ();
......@@ -309,8 +324,6 @@ while (!$killme) {
# Generate a new NS file. Be nice to not have to this, but not
# having an NS file could confuse things for the web interface.
#
my $tmpfile = "/tmp/pool-$$.nsfile";
print "Generating a new NS file in $tmpfile\n";
if (!open(NS, ">$tmpfile")) {
......@@ -355,6 +368,7 @@ while (!$killme) {
print NS "\$ns rtproto Static\n";
print NS "\$ns run\n";
close(NS);
skipns:
chmod(0775, $tmpfile);
last
......@@ -405,6 +419,8 @@ while (!$killme) {
$gotlock = 0;
}
last
if ($oneshot);
# Use a long period; we do not want the pool to change too fast.
sleep(120);
......@@ -458,7 +474,9 @@ sub fatal($)
{
my ($msg) = @_;
SENDMAIL($TBOPS, "Pool Daemon Died", $msg, $TBOPS);
SENDMAIL($TBOPS, "Pool Daemon Died", $msg, $TBOPS)
if (!($impotent || $oneshot));
$mailsent = 1;
cleanup();
die($msg);
......@@ -481,13 +499,13 @@ sub cleanup()
}
MarkDaemonStopped("pool_daemon")
if (!$impotent);
if (!($impotent || $oneshot));
}
END {
my $exitcode = $?;
if ($exitcode && !$mailsent) {
if ($exitcode && !($mailsent || $impotent || $oneshot)) {
SENDMAIL($TBOPS, "Pool Daemon Died",
"Please look at $logfile", $TBOPS);
}
......
......@@ -24,7 +24,7 @@ my $debug = 1;
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $RPCSERVER = "@OUTERBOSS_NODENAME@";
my $RPCSERVER = "@BOSSNODE@";
my $RPCPORT = "@OUTERBOSS_XMLRPCPORT@";
my $RPCCERT = "@OUTERBOSS_SSLCERTNAME@";
......
......@@ -12,6 +12,8 @@ use Sys::Syslog;
use English;
use Socket;
use Errno qw(EADDRINUSE);
use File::Basename;
use File::Path;
#
# This also kills a running frisbee.
......@@ -34,7 +36,7 @@ my $MY_IP;
my $BASEADDR = "@FRISEBEEMCASTADDR@";
my $BASEPORT = "@FRISEBEEMCASTPORT@";
my $RPCSERVER = "@OUTERBOSS_NODENAME@";
my $RPCSERVER = "@BOSSNODE@";
my $RPCPORT = "@OUTERBOSS_XMLRPCPORT@";
my $RPCCERT = "@SUBBOSS_SSLCERTNAME@";
......@@ -65,12 +67,13 @@ sub ClearPid();
sub ClearAddress();
sub Fatal($);
sub debug($);
sub GetImageInfo($$);
sub GetLoadAddress($$);
# Defines
my $FRISBEED = "$TB/sbin/frisbeed";
my $LOGFILE = "$TB/log/frisbeelauncher";
my $FRISBEEIMAGE= "$TB/sbin/frisbeeimage";
my $IMAGE_CACHE = "$TB/image_cache";
my $child_pid = 0;
my $dlfilename = 0;
......@@ -123,6 +126,7 @@ usage()
#
# XXX hack: use map + regex to get around taint check
my ($imageid, $filename, $size, $mtime) = map { /(.*)/; $1 } @ARGV;
$filename = "$IMAGE_CACHE/$filename";
#
# Get node ID via tmcc
......@@ -154,6 +158,13 @@ my $naddress;
my $address;
my $pid;