rc.mfs 3 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2004 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
# All rights reserved.
#
7
8
use English;
use Getopt::Std;
9
10

#
11
12
13
# This script is run directly from boot. It should NOT be run after
# that since some stuff is not setup to properly restart yet. For
# general reconfig or update, use rc.config instead.
14
#
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
sub usage()
{
    print "Usage: " . scriptname() . "boot|shutdown|reconfig|reset\n";
    exit(1);
}
my $optlist    = "";
my $action     = "boot";

# 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; }

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

# Script specific goo.
my $RCDIR   = "$BINDIR/rc";

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

# Protos.
sub doboot();
sub doshutdown();
sub doreconfig();
sub docleanup();

# Allow default above.
if (@ARGV) {
    $action = $ARGV[0];
}

# Execute the action.
SWITCH: for ($action) {
    /^boot$/i && do {
	doboot();
	last SWITCH;
    };
    /^shutdown$/i && do {
	doshutdown();
	last SWITCH;
    };
    /^reconfig$/i && do {
	doreconfig();
	last SWITCH;
    };
    /^reset$/i && do {
	docleanup();
	last SWITCH;
    };
    fatal("Invalid action: $action\n");
}
exit(0);
78
79

#
80
# Boot Action.
81
#
82
83
84
85
86
87
88
89
sub doboot()
{
    #
    # The MFS does a very restricted set of operations.
    #
    print("Doing Testbed Setup on an MFS\n");

    print("Informing Emulab Control that we have rebooted\n");
90
91
    if (tmcc(TMCCCMD_STATE, "MFSSETUP") < 0) {
	fatal("Error sending MFSSETUP to Emulab Control!");
92
93
94
95
96
    }

    if (-x "$RCDIR/rc.ipod") {
	print("Setting up Ping of Death\n");
	system("$RCDIR/rc.ipod");
97
	# This is allowed to fail; ipod might not be supported.
98
99
100
101
102
    }

    # Now we get into the real work.
    print("Checking Testbed reservation status\n");
    my ($pid, $eid, $vname) = bootsetup();
103

104
105
106
107
108
109
110
111
112
113
    #
    # This stuff is run regardless of reservation status.
    #
    if (-x "$RCDIR/rc.slothd") {
	print("Starting slothd usage detector\n");
	system("$RCDIR/rc.slothd start");
	if ($?) {
	    fatal("Error running $RCDIR/rc.slothd");
	}
    }
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    #
    # This is where we run all of the config scripts. These talk to the
    # DB and setup the node the way it is supposed to be. 
    # 
    if (!defined($pid)) {
	print("Resetting node to a clean state\n");
	system("$RCDIR/rc.config reset");
    }
    else {
	print("Running config scripts\n");
	system("$RCDIR/rc.config boot");
    }
    if ($?) {
	fatal("Error running $RCDIR/rc.config");
    }
    
    print("Informing Emulab Control that we are up and running\n");
    if (tmcc(TMCCCMD_STATE, "ISUP") < 0) {
	fatal("Error sending ISUP to Emulab Control!");
    }
}
136

137
138
139
140
141
142
#
# Shutdown Action.
#
sub doshutdown()
{
}
143

144
145
146
147
148
149
#
# Node Reconfig Action (without rebooting).
#
sub doreconfig()
{
}
150
151

#
152
# Node cleanup action (node is reset to completely clean state).
153
#
154
155
156
sub docleanup()
{
}