Skip to content
Snippets Groups Projects
node_admin.in 2.43 KiB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed

#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
# All rights reserved.
#

use English;
use Getopt::Std;

#
# Turn on/off admin mode for a node. 
#
sub usage()
{
    print STDOUT "Usage: nodeadmin [-h] [-n | -w] <on | off> <node>\n";
    print STDOUT "-h   This message\n";
    print STDOUT "-n   Do not reboot node\n";
    print STDOUT "-w   Wait for node to come back up if rebooted\n";
my  $optlist = "hnw";

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $BOSSADDR	= "@BOSSNODE@";

#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;

#
# Turn off line buffering on output
#
$| = 1;

#
# Untaint the path
# 
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# 
#
my $nodereboot	= "$TB/bin/node_reboot";
my $osselect    = "$TB/bin/os_select";
my $ADMINOSID   = TB_OSID_FREEBSD_MFS;
my $pxebootpath;
my $dbuid;

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (@ARGV != 2) {
    usage();
}

my $onoff  = $ARGV[0];
my $node   = $ARGV[1];

if ($onoff ne "on" && $onoff ne "off") {
    usage();
}

#
# Untaint the arguments.
#
if ($node =~ /^([-\w]+)$/) {
    $node = $1;
}
else {
    die("Tainted node name: $node");
}

#
# Verify user and get his DB uid.
#
if (! UNIX2DBUID($UID, \$dbuid)) {
    die("*** $0:\n".
	"    You do not exist in the Emulab Database.\n");
}

#
# Root and admin types can do whatever they want. Normal users can only
# run this on nodes in their own experiments.
#
if ($UID && !TBAdmin($UID)) {
    if (! TBNodeAccessCheck($UID, TB_NODEACCESS_LOADIMAGE, $node)) {
	die("*** $0:\n".
	    "    You are not allowed to boot the FreeBSD MFS on $node!\n");
    system("$osselect -t $ADMINOSID $node") and
	die("*** Failed to set temp boot to $ADMINOSID for $node!\n");
    system("$osselect -c -t $node") and
	die("*** Failed to clear temp boot for $node!\n");
DBQueryFatal("update nodes set startupcmd='', startstatus='none' ".
    my $optarg = ($options{"w"} ? "-w" : "");
	
    if (system("$nodereboot $optarg $node")) {
	"    WARNING: Could not reboot $node.\n");