[61f19e0] | 1 | #!/bin/sh |
---|
| 2 | |
---|
[4abace9] | 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. |
---|
[d53dda5] | 8 | |
---|
[4abace9] | 9 | |
---|
| 10 | # The file containing the DNS name of the current boss |
---|
[61f19e0] | 11 | BOSSNODE="/usr/local/etc/emulab/bossnode" |
---|
| 12 | |
---|
[4abace9] | 13 | # Ports that the master gateway will forward |
---|
[63f7c7e] | 14 | PORTS="139 7777" |
---|
[4abace9] | 15 | # network cat command (to listen for the gateway) |
---|
[63f7c7e] | 16 | NC="/usr/bin/nc" |
---|
[4abace9] | 17 | # Emulab rc scripts directory |
---|
[63f7c7e] | 18 | RCDIR="/usr/local/etc/emulab/rc" |
---|
| 19 | |
---|
[4abace9] | 20 | # Emulab rc script to reset accounts and federation srcipt to start the smb |
---|
| 21 | # automount process. |
---|
[63f7c7e] | 22 | RCACCT="rc.accounts" |
---|
[f3691ff] | 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 |
---|
[63f7c7e] | 46 | |
---|
[5166ad4] | 47 | # Find somewhere safe to stop |
---|
| 48 | cd /tmp |
---|
| 49 | |
---|
[61f19e0] | 50 | if [ -f $BOSSNODE ] |
---|
| 51 | then |
---|
| 52 | rm -f $BOSSNODE |
---|
| 53 | fi |
---|
| 54 | |
---|
| 55 | EMUDIR="/usr/local/etc/emulab/" |
---|
| 56 | |
---|
[63f7c7e] | 57 | # Find this experiment's stashed scripts. (Perl for advanced parsing) |
---|
[27b6aea] | 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";'` |
---|
[9c166cf] | 60 | CONFIGDIR="/proj/$PROJECT/exp/$EXP/tmp" |
---|
| 61 | SCRIPTDIR="/usr/local/federation/bin" |
---|
[61f19e0] | 62 | |
---|
[4abace9] | 63 | # Die if Scripts are not where they should be. NB, this is checked by the |
---|
| 64 | # bootstrapper, too, so a failure here is unlikely. |
---|
[9c166cf] | 65 | if [ -z "$CONFIGDIR" ] ; then |
---|
| 66 | echo "Can't find federation configs. Tmcc status says:" |
---|
[63f7c7e] | 67 | $EMUDIR/tmcc -b status |
---|
| 68 | exit 1; |
---|
| 69 | fi |
---|
| 70 | |
---|
[4450b24] | 71 | # Leave the client configuration information where clients can use it |
---|
| 72 | mkdir -p "/usr/local/federation/etc" |
---|
| 73 | cp "$CONFIGDIR/client.conf" "/usr/local/federation/etc" |
---|
| 74 | chmod 644 "/usr/local/federation/etc/client.conf" |
---|
[adcbdaf] | 75 | # Capture accounts to remove for rc.fedaccounts |
---|
| 76 | $EMUDIR/tmcc -b accounts > /usr/local/federation/etc/old_accts |
---|
| 77 | chmod 644 "/usr/local/federation/etc/old_accts" |
---|
[4450b24] | 78 | |
---|
[3c7da22] | 79 | # Get our gateway, share, and mount user from the configuration file. |
---|
| 80 | # There's probably a way to get all three at once, but this works. |
---|
[9c166cf] | 81 | GATEWAY=`$PERL -ne '/ControlGateway:\s+(.*)/i && print "$1\n";' $CONFIGDIR/client.conf` |
---|
| 82 | SHARE=`$PERL -ne '/SMBShare:\s+(.*)/i && print "$1\n";' $CONFIGDIR/client.conf` |
---|
| 83 | SMBUSER=`$PERL -ne '/ProjectUser:\s+(.*)/i && print "$1\n";' $CONFIGDIR/client.conf` |
---|
| 84 | SMBPROJECT=`$PERL -ne '/ProjectName:\s+(.*)/i && print "$1\n";' $CONFIGDIR/client.conf` |
---|
[f3691ff] | 85 | |
---|
[b09f346] | 86 | # If this is empty confusion reigns. Set a default. |
---|
[4450b24] | 87 | if [ -z "$SHARE" ]; then |
---|
[b09f346] | 88 | SHARE="USERS" |
---|
| 89 | fi |
---|
| 90 | |
---|
[291423b] | 91 | # XXX: modified seer daemon to read a config file. Not in the tarfile yet. If |
---|
| 92 | # we see one, and there's a /usr/seer/backend/daemon.py, replace that one with |
---|
| 93 | # the local one. |
---|
| 94 | if [ -e /usr/seer/backend/daemon.py ] && [ -e $SCRIPTDIR/daemon.py ]; then |
---|
| 95 | /bin/cp $SCRIPTDIR/daemon.py /usr/seer/backend/daemon.py |
---|
| 96 | fi |
---|
| 97 | |
---|
| 98 | if [ -e /usr/seer/backend/experiment-setup.py ] && [ -e $SCRIPTDIR/experiment-setup.py ]; then |
---|
| 99 | /bin/cp $SCRIPTDIR/experiment-setup.py /usr/seer/backend/experiment-setup.py |
---|
| 100 | fi |
---|
| 101 | |
---|
| 102 | # Copy the seer.conf to the local /tmp if there is one |
---|
| 103 | |
---|
[9c166cf] | 104 | if [ -e $CONFIGDIR/seer.conf ]; then |
---|
| 105 | /bin/cp $CONFIGDIR/seer.conf /tmp |
---|
[291423b] | 106 | fi |
---|
| 107 | |
---|
[4450b24] | 108 | while [ -z "$GWIP" ]; do |
---|
[b09f346] | 109 | GWIP=`host -N 10 $GATEWAY | $PERL -ne 's/.* has address // && print;'` |
---|
| 110 | echo "GWIP is $GWIP" |
---|
| 111 | sleep 10 |
---|
| 112 | done |
---|
[27b6aea] | 113 | # Copy the global hostnames file into /etc/hosts so this node can address |
---|
| 114 | # others in the experiment on other testbeds. The extra steps preserves teh |
---|
| 115 | # localhost entry that's aliased to this host's name. |
---|
| 116 | grep 127\\.0\\.0\\.1 /etc/hosts > /tmp/hosts |
---|
[9c166cf] | 117 | cat "$CONFIGDIR/hosts" >> /tmp/hosts |
---|
[27b6aea] | 118 | # If there's no node in this experiment called control, fake one so |
---|
| 119 | # that SEER events get through (if SEER's in use) |
---|
[9c166cf] | 120 | if ! grep -q control $CONFIGDIR/hosts; then |
---|
[27b6aea] | 121 | echo "$GWIP control.$EXP.$PROJECT" >> /tmp/hosts |
---|
| 122 | fi |
---|
| 123 | cp /tmp/hosts /etc/hosts && rm /tmp/hosts |
---|
| 124 | |
---|
[61f19e0] | 125 | # |
---|
| 126 | # Spin on our gateway! |
---|
| 127 | # |
---|
| 128 | |
---|
| 129 | echo "Waiting for the tunnel to come online." |
---|
| 130 | |
---|
| 131 | for port in $PORTS |
---|
| 132 | do |
---|
| 133 | until $NC -z $GATEWAY $port |
---|
| 134 | do |
---|
| 135 | sleep 5 |
---|
| 136 | done |
---|
| 137 | done |
---|
| 138 | |
---|
| 139 | # |
---|
| 140 | # Setup TMCC to use our gateway |
---|
| 141 | # |
---|
| 142 | |
---|
| 143 | echo "Configuring TMCC." |
---|
| 144 | echo $GATEWAY > $BOSSNODE |
---|
| 145 | |
---|
[adcbdaf] | 146 | # Capture new accounts for rc.fedaccounts |
---|
| 147 | $EMUDIR/tmcc -b accounts > /usr/local/federation/etc/accts |
---|
| 148 | chmod 644 "/usr/local/federation/etc/accts" |
---|
[63f7c7e] | 149 | |
---|
[61f19e0] | 150 | # |
---|
[f3691ff] | 151 | # Unmount stuff before messing with accounts |
---|
[61f19e0] | 152 | # |
---|
| 153 | |
---|
[f778038] | 154 | case `uname` in |
---|
| 155 | "FreeBSD") |
---|
| 156 | umount -A -f -t nfs,smbfs,cifs |
---|
| 157 | ;; |
---|
| 158 | "Linux") |
---|
| 159 | # Linux doesn't believe in -A so pull the filesystems out of |
---|
| 160 | # /etc/mtab and umount them individually |
---|
| 161 | for f in `$PERL -nae 'print "$F[1]\n" if $F[2] =~ /(nfs|cifs|smbfs)/;' /etc/mtab`; do |
---|
| 162 | umount -f $f |
---|
| 163 | done |
---|
| 164 | ;; |
---|
| 165 | esac |
---|
[61f19e0] | 166 | |
---|
| 167 | # |
---|
| 168 | # Setup new accounts |
---|
| 169 | # |
---|
[f3691ff] | 170 | |
---|
| 171 | # Clear the cache, just in case: |
---|
| 172 | rm -f /var/emulab/boot/tmcc/accounts |
---|
| 173 | |
---|
[adcbdaf] | 174 | /usr/local/federation/bin/rc.fedaccounts |
---|
[61f19e0] | 175 | |
---|
| 176 | # |
---|
[f3691ff] | 177 | # Call the smbmount perl script, this invokes the automounter to mount the |
---|
[4abace9] | 178 | # needed smb filesystems. |
---|
[61f19e0] | 179 | # |
---|
| 180 | echo "Mounting via SMB." |
---|
[9c166cf] | 181 | $PERL "/usr/local/federation/bin/$SMBMOUNT" $SHARE $GATEWAY $SMBUSER $SMBPROJECT |
---|
[d53dda5] | 182 | |
---|
[4abace9] | 183 | echo "Restoring old bossnode" |
---|
| 184 | # remove bossnode override |
---|
| 185 | /bin/rm -f $BOSSNODE |
---|
| 186 | # Also clear any cached data that might interfere with rourte construction. |
---|
| 187 | /bin/rm -f /var/emulab/boot/tmcc/ifconfig |
---|
| 188 | |
---|
[e26c240] | 189 | # if threr are external IP addresses that need to be configured, bring them up. |
---|
| 190 | $PERL /usr/local/federation/bin/config_from_tunnelip.pl |
---|
| 191 | |
---|
[4abace9] | 192 | # I remain unclear why ospfd seems screwed up after the resetting of accounts |
---|
| 193 | # and mounts. This seems to fix it, but it's not very satisfying. At this |
---|
| 194 | # point the federated topology is complete, so any problems with routing in a |
---|
| 195 | # partial topology -e.g. failed or partial bridging - that might have confused |
---|
| 196 | # the router should be gone. |
---|
[f3691ff] | 197 | $PKILL ospf |
---|
| 198 | $PKILL gated |
---|
| 199 | # XXX Danger, hack ahead. Apparently our FC6-SMB image and emulab disagree |
---|
| 200 | # about where gated lives. This will alias it. |
---|
| 201 | if [ ! -x /usr/sbin/gated ] ; then |
---|
| 202 | if [ -x /sbin/gated ] ; then |
---|
| 203 | ln /sbin/gated /usr/sbin/gated |
---|
| 204 | fi |
---|
| 205 | fi |
---|
[4abace9] | 206 | /usr/local/etc/emulab/rc/rc.route boot |
---|
| 207 | |
---|
[7c3008e] | 208 | # And restore the ifconfig information because SEER wants it. (SEER pulls this |
---|
| 209 | # from tmcc now |
---|
| 210 | # "$EMUDIR/tmcc" ifconfig > /var/emulab/boot/tmcc/ifconfig |
---|
| 211 | |
---|
| 212 | # SEER feels pain and confusion if times are wrong. This lays a big lick on |
---|
| 213 | # ntp sets the time directly and then restarts it. XXX FreeBSD incantation is |
---|
| 214 | # untested. |
---|
| 215 | |
---|
| 216 | case `uname` in |
---|
| 217 | "FreeBSD") |
---|
| 218 | /etc/rc.d/ntpd stop |
---|
| 219 | /usr/sbin/ntpdate boss |
---|
| 220 | /etc/rc.d/ntpd start |
---|
| 221 | ;; |
---|
| 222 | "Linux") |
---|
| 223 | /etc/rc.d/init.d/ntpd stop |
---|
| 224 | /usr/sbin/ntpdate boss |
---|
| 225 | /etc/rc.d/init.d/ntpd start |
---|
| 226 | ;; |
---|
| 227 | esac |
---|
| 228 | |
---|
[4abace9] | 229 | # Execute any command passed in as a startcmd. This basically daisy chains the |
---|
[7c3008e] | 230 | # startcmd. This needs to become a perl script to have uniform behavior here. |
---|
| 231 | echo "*$1* *$2*" |
---|
[d53dda5] | 232 | if [ ! -z "$1" ]; then |
---|
[7c3008e] | 233 | echo "calling *$1* *$2*" |
---|
| 234 | case `uname` in |
---|
| 235 | "FreeBSD") |
---|
| 236 | su -l "$1" -c "$2" |
---|
| 237 | ;; |
---|
| 238 | "Linux") |
---|
| 239 | su "$1" --command="$2" |
---|
| 240 | ;; |
---|
| 241 | esac |
---|
[d53dda5] | 242 | fi |
---|