Commit 6dacee9d authored by Mike Hibler's avatar Mike Hibler

Merge remote branch 'central/master'

parents 4aeedc82 3a9d0ae9
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 2000-2003, 2005, 2006, 2007 University of Utah and the Flux Group. * Copyright (c) 2000-2010 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <paths.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
#include <errno.h> #include <errno.h>
#include <mysql/mysql.h> #include <mysql/mysql.h>
#include <sys/time.h> #include <sys/time.h>
#include <signal.h>
#include <grp.h> #include <grp.h>
#include "capdecls.h" #include "capdecls.h"
#include "config.h" #include "config.h"
...@@ -29,6 +31,9 @@ ...@@ -29,6 +31,9 @@
static int debug = 0; static int debug = 0;
static int portnum = SERVERPORT; static int portnum = SERVERPORT;
static gid_t admingid; static gid_t admingid;
char *Pidname;
void sigterm(int);
void cleanup(void);
char *usagestr = char *usagestr =
"usage: capserver [-d] [-p #]\n" "usage: capserver [-d] [-p #]\n"
...@@ -53,6 +58,8 @@ main(int argc, char **argv) ...@@ -53,6 +58,8 @@ main(int argc, char **argv)
struct sockaddr_in name; struct sockaddr_in name;
struct timeval timeout; struct timeval timeout;
struct group *group; struct group *group;
struct sigaction sa;
sigset_t actionsigmask;
while ((ch = getopt(argc, argv, "dp:")) != -1) while ((ch = getopt(argc, argv, "dp:")) != -1)
switch(ch) { switch(ch) {
...@@ -84,6 +91,15 @@ main(int argc, char **argv) ...@@ -84,6 +91,15 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
sigemptyset(&actionsigmask);
sigaddset(&actionsigmask, SIGINT);
sigaddset(&actionsigmask, SIGTERM);
memset(&sa, 0, sizeof sa);
sa.sa_handler = sigterm;
sa.sa_mask = actionsigmask;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
/* /*
* Grab the GID for the default group. * Grab the GID for the default group.
*/ */
...@@ -129,6 +145,19 @@ main(int argc, char **argv) ...@@ -129,6 +145,19 @@ main(int argc, char **argv)
} }
syslog(LOG_NOTICE, "listening on TCP port %d", ntohs(name.sin_port)); syslog(LOG_NOTICE, "listening on TCP port %d", ntohs(name.sin_port));
if (!getuid()) {
FILE *fp;
char mybuf[BUFSIZ];
sprintf(mybuf, "%s/capserver.pid", _PATH_VARRUN);
fp = fopen(mybuf, "w");
if (fp != NULL) {
fprintf(fp, "%d\n", getpid());
(void) fclose(fp);
Pidname = strdup(mybuf);
}
}
while (1) { while (1) {
struct sockaddr_in client; struct sockaddr_in client;
int clientsock, length = sizeof(client); int clientsock, length = sizeof(client);
...@@ -295,6 +324,22 @@ main(int argc, char **argv) ...@@ -295,6 +324,22 @@ main(int argc, char **argv)
} }
close(tcpsock); close(tcpsock);
syslog(LOG_NOTICE, "daemon terminating"); syslog(LOG_NOTICE, "daemon terminating");
cleanup();
exit(0); exit(0);
} }
void
sigterm(int sig)
{
cleanup();
exit(0);
}
void
cleanup(void)
{
syslog(LOG_NOTICE, "daemon exiting by signal");
if (Pidname)
(void) unlink(Pidname);
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2007, 2009 University of Utah and the Flux Group. # Copyright (c) 2000-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use strict; use strict;
...@@ -21,6 +21,7 @@ my $optlist = "d"; ...@@ -21,6 +21,7 @@ my $optlist = "d";
# Configure variables # Configure variables
# #
my $testbed_srcdir = "@top_srcdir@"; my $testbed_srcdir = "@top_srcdir@";
my $DBNAME = "@TBDBNAME@";
# Locals # Locals
my $dbfill = "sql/database-fill.sql"; my $dbfill = "sql/database-fill.sql";
...@@ -30,7 +31,7 @@ my $tempdifffile = "/tmp/dbdiff.$$"; ...@@ -30,7 +31,7 @@ my $tempdifffile = "/tmp/dbdiff.$$";
my $tempnewfile = "/tmp/dbdiff.new.$$"; my $tempnewfile = "/tmp/dbdiff.new.$$";
my $tempoldfile = "/tmp/dbdiff.old.$$"; my $tempoldfile = "/tmp/dbdiff.old.$$";
my $exitcode = 0; my $exitcode = 0;
my $debug = 0; my $debug = 1;
my %options = (); my %options = ();
if (! getopts($optlist, \%options)) { if (! getopts($optlist, \%options)) {
...@@ -87,9 +88,9 @@ if (!$?) { ...@@ -87,9 +88,9 @@ if (!$?) {
print "*** Your installed database is out of date with $dbfill\n"; print "*** Your installed database is out of date with $dbfill\n";
print " Differences are listed in $tempdifffile\n" print " Differences are listed in $tempdifffile\n"
if ($debug); if ($debug);
print " To bring it up to date, run: \n"; print " As a safety measure, you will not be able to install until this\n";
print " mysqldump tbdb > tbdb.backup\n"; print " is resolved.\n";
print " (cd db; mysql tbdb < $master_fill)\n";
unlink($tempdifffile) unlink($tempdifffile)
if (!$debug); if (!$debug);
exit(1); exit(1);
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2009 University of Utah and the Flux Group. # Copyright (c) 2009-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use strict; use strict;
...@@ -13,16 +13,20 @@ use Getopt::Std; ...@@ -13,16 +13,20 @@ use Getopt::Std;
# #
sub usage() sub usage()
{ {
print STDERR "Usage: dbupdate [-s | -f] <dbname> [<version>]\n"; print STDERR "Usage: dbupdate [-v] [-s] [-f] <dbname> [<version>]\n";
exit(-1); exit(-1);
} }
my $optlist = "dsf"; my $optlist = "dsfvp:q";
my $debug = 0; my $debug = 0;
my $force = 0; my $force = 0;
my $single = 0; my $single = 0;
my $verify = 0;
my $quiet = 0;
my $path;
my $dbname; my $dbname;
my $version; my $version;
my $dbnumber = 0; # XXX Core emulab code is very rigid. my $dbnumber = 0; # XXX Core emulab code is very rigid.
my $verify_count = 0;
# #
# Configure variables # Configure variables
...@@ -30,6 +34,7 @@ my $dbnumber = 0; # XXX Core emulab code is very rigid. ...@@ -30,6 +34,7 @@ my $dbnumber = 0; # XXX Core emulab code is very rigid.
my $TB = "@prefix@"; my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $DEFDBNAME = "@TBDBNAME@"; my $DEFDBNAME = "@TBDBNAME@";
my $testbed_srcdir = "@top_srcdir@";
# Protos # Protos
sub Fatal($); sub Fatal($);
...@@ -44,11 +49,24 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; ...@@ -44,11 +49,24 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# #
$| = 1; $| = 1;
# Load the Testbed support stuff. #
use lib "@prefix@/lib"; # Do not modify the include path if it was specified when invoked.
# This allows update to run from the build tree.
#
BEGIN
{
eval "require emdbi";
if ($@) {
unshift(@INC, "@prefix@/lib");
}
}
use emdbi; use emdbi;
use libtestbed; use libtestbed;
# Need this below.
my $objdir = `/bin/pwd`;
chomp($objdir);
# #
# Parse command arguments. # Parse command arguments.
# #
...@@ -62,6 +80,17 @@ if (defined($options{"d"})) { ...@@ -62,6 +80,17 @@ if (defined($options{"d"})) {
if (defined($options{"f"})) { if (defined($options{"f"})) {
$force = 1; $force = 1;
} }
if (defined($options{"q"})) {
$quiet = 1;
}
if (defined($options{"v"})) {
$verify = 1;
}
if (defined($options{"p"})) {
$path = $options{"p"};
chdir($path) or
Fatal("$path does not exist");
}
if (defined($options{"s"})) { if (defined($options{"s"})) {
$single = 1; $single = 1;
if (@ARGV != 2) { if (@ARGV != 2) {
...@@ -172,6 +201,12 @@ foreach my $file (@files) { ...@@ -172,6 +201,12 @@ foreach my $file (@files) {
my $revision = join(".", @dots); my $revision = join(".", @dots);
$revision .= (@dots ? "." : "") . $file; $revision .= (@dots ? "." : "") . $file;
if ($verify) {
print "Need DB update $fullpath\n";
$verify_count++;
next;
}
print "Processing update $fullpath\n"; print "Processing update $fullpath\n";
# Undefine this to make sure we get a new version each file. # Undefine this to make sure we get a new version each file.
...@@ -193,7 +228,18 @@ foreach my $file (@files) { ...@@ -193,7 +228,18 @@ foreach my $file (@files) {
"where name='dbrev'") "where name='dbrev'")
if (!$single && !$force); if (!$single && !$force);
} }
if ($verify) {
exit($verify_count)
if (!$verify_count || $quiet);
my $updatedir = "$testbed_srcdir/sql/updates";
$updatedir =~ s/^\.\.\///;
print "*** Your have DB update scripts that have not been run.\n";
print " As a safety measure, you will not be able to install until\n";
print " this is resolved.\n";
exit($verify_count);
}
exit(0); exit(0);
sub Fatal($) sub Fatal($)
...@@ -203,3 +249,4 @@ sub Fatal($) ...@@ -203,3 +249,4 @@ sub Fatal($)
die("*** $0:\n". die("*** $0:\n".
" $msg\n"); " $msg\n");
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2009 University of Utah and the Flux Group. # Copyright (c) 2000-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use strict; use strict;
...@@ -58,25 +58,9 @@ my $diff = (system("$schemadiff $db_schema $master_schema") >> 8); ...@@ -58,25 +58,9 @@ my $diff = (system("$schemadiff $db_schema $master_schema") >> 8);
unlink($db_schema); unlink($db_schema);
if ($diff) { if ($diff) {
my $objdir = `/bin/pwd`; print "*** Your DB schema are out of date with $master_schema\n";
chomp($objdir); print " As a safety measure, you will not be able to install until\n";
print " this is resolved.\n";
print << "EOSTR";
The schema from $master_schema differs from
the running database. As a safety measure, you will not be able to
install until this is resolved.
If you are a user of the emulab software outside of Utah, this is
probably because your database was created for an older version of the
emulab software. You can update your database by:
boss> cd /your/srcdir/sql/updates
boss> perl $objdir/dbupdate $DBNAME
Be sure look in /your/srcdir/doc/UPDATING for any other instructions.
EOSTR
exit(1); exit(1);
} else { } else {
exit(0); exit(0);
......
...@@ -82,15 +82,9 @@ my $diff = (system("$sitevarsdiff $db_sitevars $master_sitevars") >> 8); ...@@ -82,15 +82,9 @@ my $diff = (system("$sitevarsdiff $db_sitevars $master_sitevars") >> 8);
unlink($db_sitevars); unlink($db_sitevars);
if ($diff) { if ($diff) {
print "*** Your sitevariables are out of date with $master_sitevars.\n";
print << "EOSTR"; print " As a safety measure, you will not be able to install until\n";
print " this is resolved.\n";
The sitevariables from $master_sitevars differs from
the running database. As a safety measure, you will not be able to install
until this is resolved. Please see the SQL statements above.
EOSTR
exit(1); exit(1);
} else { } else {
exit(0); exit(0);
......
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2009 University of Utah and the Flux Group. # Copyright (c) 2000-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
...@@ -12,7 +12,8 @@ SUBDIR = install ...@@ -12,7 +12,8 @@ SUBDIR = install
include $(OBJDIR)/Makeconf include $(OBJDIR)/Makeconf
ifeq ($(STANDALONE_CLEARINGHOUSE),0) ifeq ($(STANDALONE_CLEARINGHOUSE),0)
TARGETS = boss-install ops-install fs-install dump-descriptors load-descriptors TARGETS = libinstall.pm boss-install ops-install fs-install dump-descriptors \
load-descriptors update-install update-testbed
else else
TARGETS = clrhouse-install TARGETS = clrhouse-install
endif endif
...@@ -25,7 +26,10 @@ all: $(TARGETS) ...@@ -25,7 +26,10 @@ all: $(TARGETS)
include $(TESTBED_SRCDIR)/GNUmakerules include $(TESTBED_SRCDIR)/GNUmakerules
install: $(INSTALL_LIBDIR)/libinstall.pm install: $(INSTALL_LIBDIR)/libinstall.pm \
$(INSTALL_SBINDIR)/update-install \
$(INSTALL_SBINDIR)/update-testbed
clean: clean:
rm -f boss-install ops-install fs-install rm -f boss-install ops-install fs-install update-install
rm -f update-testbed
...@@ -66,7 +66,6 @@ my $PWD = "/bin/pwd"; ...@@ -66,7 +66,6 @@ my $PWD = "/bin/pwd";
my $PW = "/usr/sbin/pw"; my $PW = "/usr/sbin/pw";
my $PATCH = "/usr/bin/patch"; my $PATCH = "/usr/bin/patch";
my $SSH_KEYGEN = "/usr/bin/ssh-keygen"; my $SSH_KEYGEN = "/usr/bin/ssh-keygen";
my $PKG_INFO = "/usr/sbin/pkg_info";
my $PKG_ADD = "/usr/sbin/pkg_add"; my $PKG_ADD = "/usr/sbin/pkg_add";
my $PKG_DEL = "/usr/sbin/pkg_delete"; my $PKG_DEL = "/usr/sbin/pkg_delete";
my $TOUCH = "/usr/bin/touch"; my $TOUCH = "/usr/bin/touch";
...@@ -87,8 +86,6 @@ my $MYSQLDUMP = "/usr/local/bin/mysqldump"; ...@@ -87,8 +86,6 @@ my $MYSQLDUMP = "/usr/local/bin/mysqldump";
my $MYSQLINSTALL = "/usr/local/bin/mysql_install_db"; my $MYSQLINSTALL = "/usr/local/bin/mysql_install_db";
my $MYSQLDBDIR = "/var/db/mysql"; my $MYSQLDBDIR = "/var/db/mysql";
my $GMAKE = "/usr/local/bin/gmake";
# #
# Some files we edit/create # Some files we edit/create
# #
...@@ -170,17 +167,13 @@ my $NAMED_PIDFILE = "/var/run/named.pid"; ...@@ -170,17 +167,13 @@ my $NAMED_PIDFILE = "/var/run/named.pid";
# #
# Some directories we care about # Some directories we care about
# #
my $LOGDIR = "$PREFIX/log";
my $MYSQL_LOGDIR = "$LOGDIR/mysql"; my $MYSQL_LOGDIR = "$LOGDIR/mysql";
my $RCDIR = "/usr/local/etc/rc.d";
my $USERSVAR_DIR = "$PREFIX/usersvar"; my $USERSVAR_DIR = "$PREFIX/usersvar";
my $OPSDIR_DIR = "$PREFIX/opsdir"; my $OPSDIR_DIR = "$PREFIX/opsdir";
my $PORTSDIR = "/usr/ports";
my $PORTSMISCDIR = "$PORTSDIR/misc"; my $PORTSMISCDIR = "$PORTSDIR/misc";
my $MIBPATH = "/usr/local/share/snmp/mibs"; my $MIBPATH = "/usr/local/share/snmp/mibs";
my $TFTP_DIR = "$PREFIX/tftpboot"; my $TFTP_DIR = "$PREFIX/tftpboot";
my $TFTP_PROJ_DIR = "$TFTP_DIR/proj"; my $TFTP_PROJ_DIR = "$TFTP_DIR/proj";
my $VARRUN = "/var/run";
my $ETCSSH = "/etc/ssh"; my $ETCSSH = "/etc/ssh";
# #
......
...@@ -142,12 +142,10 @@ my $PW = "/usr/sbin/pw"; ...@@ -142,12 +142,10 @@ my $PW = "/usr/sbin/pw";
my $PATCH = "/usr/bin/patch"; my $PATCH = "/usr/bin/patch";
my $NEWALIASES = "/usr/bin/newaliases"; my $NEWALIASES = "/usr/bin/newaliases";
my $SH = "/bin/sh"; my $SH = "/bin/sh";
my $PKG_INFO = "/usr/sbin/pkg_info";
my $PKG_ADD = "/usr/sbin/pkg_add"; my $PKG_ADD = "/usr/sbin/pkg_add";
my $PWD = "/bin/pwd"; my $PWD = "/bin/pwd";
my $CP = "/bin/cp"; my $CP = "/bin/cp";
my $MV = "/bin/mv"; my $MV = "/bin/mv";
my $GMAKE = "/usr/local/bin/gmake";
my $ENV = "/usr/bin/env"; my $ENV = "/usr/bin/env";
my $QUOTAON = "/usr/sbin/quotaon"; my $QUOTAON = "/usr/sbin/quotaon";
...@@ -175,11 +173,8 @@ my $SMBCONF_HEAD = "$SMBCONF_FILE.head"; ...@@ -175,11 +173,8 @@ my $SMBCONF_HEAD = "$SMBCONF_FILE.head";
# #
my $LIST_DIR = "/etc/mail/lists"; my $LIST_DIR = "/etc/mail/lists";
my $TIPLOG_DIR = "/var/log/tiplogs"; my $TIPLOG_DIR = "/var/log/tiplogs";
my $PORTSDIR = "/usr/ports";
my $PORTSMISCDIR = "$PORTSDIR/misc"; my $PORTSMISCDIR = "$PORTSDIR/misc";
my $SRCDIR = '@srcdir@'; my $SRCDIR = '@srcdir@';
my $RCDIR = "/usr/local/etc/rc.d";
my $VARRUN = "/var/run";
# #
# And some lists that we use # And some lists that we use
......
...@@ -4,12 +4,31 @@ ...@@ -4,12 +4,31 @@
# Copyright (c) 2003-2010 University of Utah and the Flux Group. # Copyright (c) 2003-2010 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
# #
# A simple library for use in the installation scripts, to make them seem a # A simple library for use in the installation scripts, to make them
# little more legitimate, instead of the quick hacks they are. # seem a little more legitimate, instead of the quick hacks they are.
# #
use POSIX qw(strftime); use POSIX qw(strftime);
use Exporter;
use vars qw(@EXPORT $TOP_OBJDIR
$TBROOT $LOGDIR $MAINSITE $PGENISUPPORT $GMAKE $PKG_INFO
$PORTSDIR $VARRUN $RCDIR);
@EXPORT = qw($TOP_OBJDIR
$TBROOT $LOGDIR $MAINSITE $PGENISUPPORT $GMAKE $PKG_INFO
$PORTSDIR $VARRUN $RCDIR);
# Configure variables
$TBROOT = "@prefix@";
$LOGDIR = "$TBROOT/log";
$MAINSITE = @TBMAINSITE@;
$PGENISUPPORT = @PROTOGENI_SUPPORT@;
$GMAKE = "/usr/local/bin/gmake";
$PKG_INFO = "/usr/sbin/pkg_info";
$PORTSDIR = "/usr/ports";
$VARRUN = "/var/run";
$RCDIR = "/usr/local/etc/rc.d";
# #
# Make sure that output gets printed right away # Make sure that output gets printed right away
...@@ -32,11 +51,24 @@ my $updatemode = 0; ...@@ -32,11 +51,24 @@ my $updatemode = 0;
# Used by update-install to bump the version number. # Used by update-install to bump the version number.
sub SET_TESTBED_VERSION($) { $updatemode = $MAGIC_TESTBED_VERSION = $_[0]; } sub SET_TESTBED_VERSION($) { $updatemode = $MAGIC_TESTBED_VERSION = $_[0]; }
# Set by update-install.
my $impotent = 0;
my $logfp;
sub SET_IMPOTENT_MODE($) { $impotent = 1; $logfp = $_[0]; };
# #
# Some programs we may call # Some programs we may call
# #
my $FETCH = "/usr/bin/fetch"; my $FETCH = "/usr/bin/fetch";
#
# Figure out which directory we live in, so that some stages can do thing
# relative to it.
#
$TOP_OBJDIR = `/usr/bin/dirname $0`;
chomp $TOP_OBJDIR;
$TOP_OBJDIR = "$TOP_OBJDIR/..";
# #
# Let's pretend perl's exception mechanism has a sane name for the function # Let's pretend perl's exception mechanism has a sane name for the function
# that raises an exception # that raises an exception
...@@ -44,7 +76,7 @@ my $FETCH = "/usr/bin/fetch"; ...@@ -44,7 +76,7 @@ my $FETCH = "/usr/bin/fetch";
sub throw(@) { sub throw(@) {
die @_,"\n"; die @_,"\n";
} }
# #
# Start a new installation phase # Start a new installation phase
# #
...@@ -80,12 +112,15 @@ sub Phase($$$) { ...@@ -80,12 +112,15 @@ sub Phase($$$) {
print "\n"; print "\n";
} }
printf "%-50s", $descrstring; printf "%-50s", $descrstring;
printf $logfp "%-50s", $descrstring
if ($impotent);