Newer
Older
#!/usr/bin/perl -wT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
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";
exit(-1);
}
#
# 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 ($options{h}) {
usage();
}
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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");
}
}
if ($onoff eq "on") {
system("$osselect -t $ADMINOSID $node") and
die("*** Failed to set temp boot to $ADMINOSID for $node!\n");
}
else {
system("$osselect -c -t $node") and
die("*** Failed to clear temp boot for $node!\n");
}
DBQueryFatal("update nodes set startupcmd='', startstatus='none' ".
"where node_id='$node'");
#
# Reboot node
#
if (!$options{n}) {
my $optarg = ($options{"w"} ? "-w" : "");
if (system("$nodereboot $optarg $node")) {
die("*** $0:\n".
" WARNING: Could not reboot $node.\n");
}
exit(0);