bootvnodes 3.5 KB
Newer Older
1
2
3
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# All rights reserved.
#
use Getopt::Std;
use English;
use Errno;
use POSIX qw(strftime);

#
# Startup vnodes, if there are any!
#
# NB: This script should not be run in foreground mode on a remote node
# when booting; if boss is down the boot will hang. On local nodes, its
# okay to hang.
#
sub usage()
{
21
    print "Usage: bootvnodes [-d] [-f] [-k | -h]\n";
22
23
    exit(1);
}
24
my $optlist = "kdfh";
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

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

# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }

#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself. 
# 
use libsetup;

# Locals
my $logname = "$LOGDIR/bootvnodes.debug";
my $vndir   = "/var/emulab/jails";
my $debug   = 0;
my $daemon  = 1;
45
46
my $killit  = 0;
my $haltit  = 0;
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

#
# Forward declarations for prototype checking
#
sub bootvnodes();

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{"d"})) {
    $debug  = 1;
}
if (defined($options{"f"})) {
    $daemon = 0;
}
67
68
69
70
71
72
if (defined($options{"k"})) {
    $killit = 1;
}
if (defined($options{"h"})) {
    $haltit = 1;
}
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
104
105
if (@ARGV) {
    usage();
}

#
# Must be root.
# 
if ($UID != 0) {
    die("*** $0:\n".
	"    Must be root to run this script!\n");
}

#
# XXX
# Do not run the vnode startup on Linux nodes yet.
#
my $sysname = `uname -s`;
chomp($sysname);
if ($sysname eq "Linux") {
    exit(0);
}

#
# Put this into the background and log its output. We *must* do this cause
# we do not want to halt the boot if the testbed is down!
# 
if ($daemon && TBBackGround($logname)) {
    #
    # Parent exits normally
    #
    exit(0);
}

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
if ($killit | $haltit) {
    my $opt = ($haltit ? "-h" : "-k");
    my $act = ($haltit ? "Halting" : "Killing");
    
    print "$act vnodes ... please be patient ...\n";

    opendir(DIR, "/var/emulab/jails") or
	die("Cannot opendir /var/emulab/jails: $!\n");
    my @files = readdir(DIR);
    closedir(DIR);

    foreach my $file (@files) {
	if ($file ne "." && $file ne ".." &&
	    $file =~ /^([-\w]*)$/) {

	    print "$act vnode $1 ...\n";
	    system("vnodesetup $opt $1");
	}
    }
    exit(0);
}

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
my %curvnodelist;
my @vnodes;

#
# Get the current set of vnodes that are supposed to be running on
# this node.
#
my $TM = OPENTMCC(TMCCCMD_VNODELIST);
while (<$TM>) {
    if ($_ =~ /^VNODEID=([-\w]+) JAILED=(\d)$/) {
	$curvnodelist{$1} = $2;
    }
    else {
	print "Skipping bad vnodeid: '$_'\n";
    }
}
CLOSETMCC($TM);

@vnodes = keys(%curvnodelist);
if (! @vnodes) {
    print "No vnodes. Exiting gracefully ...\n";
    exit(0);
}
print "Vnodelist is @vnodes.\n";

153
154
155
156
#
# If booting with vnodes, then see about creating the extra FS.
# This will fail if it already exists. Keep going on any failure though.
#
157
158
159
if (!REMOTE()) {
    system("mkextrafs.pl $vndir");
}
160

161
162
163
164
165
166
167
168
169
170
#
# Make sure enough vn devices exist
#
for (my $i = 0; $i < scalar(@vnodes); $i++) {
    my $dev = "vn${i}";
    if (! -e "/dev/${dev}c") {
        system("(cd /dev; ./MAKEDEV $dev)");
    }
}

171
172
173
foreach my $vnode (keys(%curvnodelist)) {
    my $jailflag = "";
    if ($curvnodelist{$vnode}) {
174
	$jailflag = "-jV";
175
176
    }
    print "Setting up vnode $vnode ...\n";
177
    # This will not return until the vnode is fully running.
178
    system("vnodesetup -b $jailflag $vnode");
179
    sleep(1);
180
181
}
exit(0);