1 | #!/bin/sh |
---|
2 | |
---|
3 | # Set up a federated environment on a client. Unmount all local file systems, |
---|
4 | # erase all local accounts and then bring in accounts and file systems from the |
---|
5 | # master testbed. Once all that's done, restore client communication to the |
---|
6 | # local bossnode and execute any startup command passed in as arguments to this |
---|
7 | # script. |
---|
8 | |
---|
9 | |
---|
10 | # The file containing the DNS name of the current boss |
---|
11 | BOSSNODE="/usr/local/etc/emulab/bossnode" |
---|
12 | |
---|
13 | # Ports that the master gateway will forward |
---|
14 | PORTS="139 7777" |
---|
15 | # network cat command (to listen for the gateway) |
---|
16 | NC="/usr/bin/nc" |
---|
17 | # Emulab rc scripts directory |
---|
18 | RCDIR="/usr/local/etc/emulab/rc" |
---|
19 | |
---|
20 | # Emulab rc script to reset accounts and federation srcipt to start the smb |
---|
21 | # automount process. |
---|
22 | RCACCT="rc.accounts" |
---|
23 | SMBMOUNT="smbmount.`uname`.pl" |
---|
24 | |
---|
25 | # Find the right version of pkill. For killing. |
---|
26 | if [ -x "/usr/bin/pkill" ] ; then |
---|
27 | PKILL="/usr/bin/pkill" |
---|
28 | else |
---|
29 | if [ -x "/bin/pkill" ] ; then |
---|
30 | PKILL="/bin/pkill" |
---|
31 | else |
---|
32 | PKILL="echo" |
---|
33 | fi |
---|
34 | fi |
---|
35 | |
---|
36 | if [ -x "/usr/bin/perl" ]; then |
---|
37 | PERL="/usr/bin/perl" |
---|
38 | else |
---|
39 | if [ -x "/usr/local/bin/perl" ]; then |
---|
40 | PERL="/usr/local/bin/perl" |
---|
41 | else |
---|
42 | # Wing it... |
---|
43 | PERL="perl" |
---|
44 | fi |
---|
45 | fi |
---|
46 | |
---|
47 | # Find somewhere safe to stop |
---|
48 | cd /tmp |
---|
49 | |
---|
50 | if [ -f $BOSSNODE ] |
---|
51 | then |
---|
52 | rm -f $BOSSNODE |
---|
53 | fi |
---|
54 | |
---|
55 | EMUDIR="/usr/local/etc/emulab/" |
---|
56 | |
---|
57 | # Find this experiment's stashed scripts. (Perl for advanced parsing) |
---|
58 | PROJECT=`$EMUDIR/tmcc -b status | $PERL -ne '/ALLOCATED=([^\/]+)\/([^\s]+)/ && print "$1\n";'` |
---|
59 | EXP=`$EMUDIR/tmcc -b status | $PERL -ne '/ALLOCATED=([^\/]+)\/([^\s]+)/ && print "$2\n";'` |
---|
60 | SCRIPTDIR="/proj/$PROJECT/exp/$EXP/tmp" |
---|
61 | |
---|
62 | # Die if Scripts are not where they should be. NB, this is checked by the |
---|
63 | # bootstrapper, too, so a failure here is unlikely. |
---|
64 | if [ -z "$SCRIPTDIR" ] ; then |
---|
65 | echo "Can't find federation scripts. Tmcc status says:" |
---|
66 | $EMUDIR/tmcc -b status |
---|
67 | exit 1; |
---|
68 | fi |
---|
69 | |
---|
70 | # Get our gateway, share, and mount user from the configuration file. |
---|
71 | # There's probably a way to get all three at once, but this works. |
---|
72 | GATEWAY=`$PERL -ne '/ControlGateway:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
73 | SHARE=`$PERL -ne '/SMBShare:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
74 | SMBUSER=`$PERL -ne '/ProjectUser:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
75 | SMBPROJECT=`$PERL -ne '/ProjectName:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
76 | |
---|
77 | GWIP=`host -N 10 $GATEWAY | $PERL -ne 's/.* has address // && print;'` |
---|
78 | # Copy the global hostnames file into /etc/hosts so this node can address |
---|
79 | # others in the experiment on other testbeds. The extra steps preserves teh |
---|
80 | # localhost entry that's aliased to this host's name. |
---|
81 | grep 127\\.0\\.0\\.1 /etc/hosts > /tmp/hosts |
---|
82 | cat "$SCRIPTDIR/hosts" >> /tmp/hosts |
---|
83 | # If there's no node in this experiment called control, fake one so |
---|
84 | # that SEER events get through (if SEER's in use) |
---|
85 | if ! grep -q control $SCRIPTDIR/hosts; then |
---|
86 | echo "$GWIP control.$EXP.$PROJECT" >> /tmp/hosts |
---|
87 | fi |
---|
88 | cp /tmp/hosts /etc/hosts && rm /tmp/hosts |
---|
89 | |
---|
90 | # XXX: |
---|
91 | # The standard emulab rc.accounts script won't replace existing user accounts |
---|
92 | # with our new ones, so we have to patch it to do so. This is obviously pretty |
---|
93 | # fragile and needs to change. To make matters worse, our FBSD62-SMB images |
---|
94 | # contain the patched rc.accounts, so this patching step will fail there. |
---|
95 | cd "$EMUDIR/rc" |
---|
96 | patch -f < /tmp/rc.accounts.patch |
---|
97 | cd /tmp |
---|
98 | |
---|
99 | # |
---|
100 | # Spin on our gateway! |
---|
101 | # |
---|
102 | |
---|
103 | echo "Waiting for the tunnel to come online." |
---|
104 | |
---|
105 | for port in $PORTS |
---|
106 | do |
---|
107 | until $NC -z $GATEWAY $port |
---|
108 | do |
---|
109 | sleep 5 |
---|
110 | done |
---|
111 | done |
---|
112 | |
---|
113 | # |
---|
114 | # Setup TMCC to use our gateway |
---|
115 | # |
---|
116 | |
---|
117 | echo "Configuring TMCC." |
---|
118 | echo $GATEWAY > $BOSSNODE |
---|
119 | |
---|
120 | |
---|
121 | # |
---|
122 | # Unmount stuff before messing with accounts |
---|
123 | # |
---|
124 | |
---|
125 | case `uname` in |
---|
126 | "FreeBSD") |
---|
127 | umount -A -f -t nfs,smbfs,cifs |
---|
128 | ;; |
---|
129 | "Linux") |
---|
130 | # Linux doesn't believe in -A so pull the filesystems out of |
---|
131 | # /etc/mtab and umount them individually |
---|
132 | for f in `$PERL -nae 'print "$F[1]\n" if $F[2] =~ /(nfs|cifs|smbfs)/;' /etc/mtab`; do |
---|
133 | umount -f $f |
---|
134 | done |
---|
135 | ;; |
---|
136 | esac |
---|
137 | |
---|
138 | # |
---|
139 | # Setup new accounts |
---|
140 | # |
---|
141 | |
---|
142 | # Clear the cache, just in case: |
---|
143 | rm -f /var/emulab/boot/tmcc/accounts |
---|
144 | |
---|
145 | $RCDIR/rc.accounts reconfig |
---|
146 | |
---|
147 | # |
---|
148 | # Call the smbmount perl script, this invokes the automounter to mount the |
---|
149 | # needed smb filesystems. |
---|
150 | # |
---|
151 | echo "Mounting via SMB." |
---|
152 | $PERL "/tmp/$SMBMOUNT" $SHARE $GATEWAY $SMBUSER $SMBPROJECT |
---|
153 | |
---|
154 | echo "Restoring old bossnode" |
---|
155 | # remove bossnode override |
---|
156 | /bin/rm -f $BOSSNODE |
---|
157 | # Also clear any cached data that might interfere with rourte construction. |
---|
158 | /bin/rm -f /var/emulab/boot/tmcc/ifconfig |
---|
159 | |
---|
160 | # I remain unclear why ospfd seems screwed up after the resetting of accounts |
---|
161 | # and mounts. This seems to fix it, but it's not very satisfying. At this |
---|
162 | # point the federated topology is complete, so any problems with routing in a |
---|
163 | # partial topology -e.g. failed or partial bridging - that might have confused |
---|
164 | # the router should be gone. |
---|
165 | $PKILL ospf |
---|
166 | $PKILL gated |
---|
167 | # XXX Danger, hack ahead. Apparently our FC6-SMB image and emulab disagree |
---|
168 | # about where gated lives. This will alias it. |
---|
169 | if [ ! -x /usr/sbin/gated ] ; then |
---|
170 | if [ -x /sbin/gated ] ; then |
---|
171 | ln /sbin/gated /usr/sbin/gated |
---|
172 | fi |
---|
173 | fi |
---|
174 | /usr/local/etc/emulab/rc/rc.route boot |
---|
175 | |
---|
176 | # And restore the ifconfig information because SEER wants it. (SEER pulls this |
---|
177 | # from tmcc now |
---|
178 | # "$EMUDIR/tmcc" ifconfig > /var/emulab/boot/tmcc/ifconfig |
---|
179 | |
---|
180 | # SEER feels pain and confusion if times are wrong. This lays a big lick on |
---|
181 | # ntp sets the time directly and then restarts it. XXX FreeBSD incantation is |
---|
182 | # untested. |
---|
183 | |
---|
184 | case `uname` in |
---|
185 | "FreeBSD") |
---|
186 | /etc/rc.d/ntpd stop |
---|
187 | /usr/sbin/ntpdate boss |
---|
188 | /etc/rc.d/ntpd start |
---|
189 | ;; |
---|
190 | "Linux") |
---|
191 | /etc/rc.d/init.d/ntpd stop |
---|
192 | /usr/sbin/ntpdate boss |
---|
193 | /etc/rc.d/init.d/ntpd start |
---|
194 | ;; |
---|
195 | esac |
---|
196 | |
---|
197 | # Execute any command passed in as a startcmd. This basically daisy chains the |
---|
198 | # startcmd. This needs to become a perl script to have uniform behavior here. |
---|
199 | echo "*$1* *$2*" |
---|
200 | if [ ! -z "$1" ]; then |
---|
201 | echo "calling *$1* *$2*" |
---|
202 | case `uname` in |
---|
203 | "FreeBSD") |
---|
204 | su -l "$1" -c "$2" |
---|
205 | ;; |
---|
206 | "Linux") |
---|
207 | su "$1" --command="$2" |
---|
208 | ;; |
---|
209 | esac |
---|
210 | fi |
---|