[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) |
---|
[f3691ff] | 58 | SCRIPTDIR=`$EMUDIR/tmcc -b status | $PERL -ne '/ALLOCATED=([^\/]+)\/([^\s]+)/ && print "/proj/$1/exp/$2/tmp\n";'` |
---|
[61f19e0] | 59 | |
---|
[4abace9] | 60 | # Die if Scripts are not where they should be. NB, this is checked by the |
---|
| 61 | # bootstrapper, too, so a failure here is unlikely. |
---|
[63f7c7e] | 62 | if [ -z "$SCRIPTDIR" ] ; then |
---|
| 63 | echo "Can't find federation scripts. Tmcc status says:" |
---|
| 64 | $EMUDIR/tmcc -b status |
---|
| 65 | exit 1; |
---|
| 66 | fi |
---|
| 67 | |
---|
| 68 | # Copy the global hostnames file into /etc/hosts so this node can address |
---|
[4abace9] | 69 | # others in the experiment on other testbeds. The extra steps preserves teh |
---|
| 70 | # localhost entry that's aliased to this host's name. |
---|
[63f7c7e] | 71 | grep 127\\.0\\.0\\.1 /etc/hosts > /tmp/hosts |
---|
| 72 | cat "$SCRIPTDIR/hosts" >> /tmp/hosts |
---|
| 73 | cp /tmp/hosts /etc/hosts && rm /tmp/hosts |
---|
| 74 | |
---|
[3c7da22] | 75 | # Get our gateway, share, and mount user from the configuration file. |
---|
| 76 | # There's probably a way to get all three at once, but this works. |
---|
[f3691ff] | 77 | GATEWAY=`$PERL -ne '/ControlGateway:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
| 78 | SHARE=`$PERL -ne '/SMBShare:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
| 79 | SMBUSER=`$PERL -ne '/ProjectUser:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
| 80 | SMBPROJECT=`$PERL -ne '/ProjectName:\s+(.*)/i && print "$1\n";' $SCRIPTDIR/client.conf` |
---|
| 81 | |
---|
| 82 | # XXX: |
---|
| 83 | # The standard emulab rc.accounts script won't replace existing user accounts |
---|
| 84 | # with our new ones, so we have to patch it to do so. This is obviously pretty |
---|
| 85 | # fragile and needs to change. To make matters worse, our FBSD62-SMB images |
---|
| 86 | # contain the patched rc.accounts, so this patching step will fail there. |
---|
| 87 | cd "$EMUDIR/rc" |
---|
| 88 | patch -f < /tmp/rc.accounts.patch |
---|
| 89 | cd /tmp |
---|
[61f19e0] | 90 | |
---|
| 91 | # |
---|
| 92 | # Spin on our gateway! |
---|
| 93 | # |
---|
| 94 | |
---|
| 95 | echo "Waiting for the tunnel to come online." |
---|
| 96 | |
---|
| 97 | for port in $PORTS |
---|
| 98 | do |
---|
| 99 | until $NC -z $GATEWAY $port |
---|
| 100 | do |
---|
| 101 | sleep 5 |
---|
| 102 | done |
---|
| 103 | done |
---|
| 104 | |
---|
| 105 | # |
---|
| 106 | # Setup TMCC to use our gateway |
---|
| 107 | # |
---|
| 108 | |
---|
| 109 | echo "Configuring TMCC." |
---|
| 110 | echo $GATEWAY > $BOSSNODE |
---|
| 111 | |
---|
[63f7c7e] | 112 | |
---|
[61f19e0] | 113 | # |
---|
[f3691ff] | 114 | # Unmount stuff before messing with accounts |
---|
[61f19e0] | 115 | # |
---|
| 116 | |
---|
[f778038] | 117 | case `uname` in |
---|
| 118 | "FreeBSD") |
---|
| 119 | umount -A -f -t nfs,smbfs,cifs |
---|
| 120 | ;; |
---|
| 121 | "Linux") |
---|
| 122 | # Linux doesn't believe in -A so pull the filesystems out of |
---|
| 123 | # /etc/mtab and umount them individually |
---|
| 124 | for f in `$PERL -nae 'print "$F[1]\n" if $F[2] =~ /(nfs|cifs|smbfs)/;' /etc/mtab`; do |
---|
| 125 | umount -f $f |
---|
| 126 | done |
---|
| 127 | ;; |
---|
| 128 | esac |
---|
[61f19e0] | 129 | |
---|
| 130 | # |
---|
| 131 | # Setup new accounts |
---|
| 132 | # |
---|
[f3691ff] | 133 | |
---|
| 134 | # Clear the cache, just in case: |
---|
| 135 | rm -f /var/emulab/boot/tmcc/accounts |
---|
| 136 | |
---|
[61f19e0] | 137 | $RCDIR/rc.accounts reconfig |
---|
| 138 | |
---|
| 139 | # |
---|
[f3691ff] | 140 | # Call the smbmount perl script, this invokes the automounter to mount the |
---|
[4abace9] | 141 | # needed smb filesystems. |
---|
[61f19e0] | 142 | # |
---|
| 143 | echo "Mounting via SMB." |
---|
[f3691ff] | 144 | $PERL "/tmp/$SMBMOUNT" $SHARE $GATEWAY $SMBUSER $SMBPROJECT |
---|
[d53dda5] | 145 | |
---|
[4abace9] | 146 | echo "Restoring old bossnode" |
---|
| 147 | # remove bossnode override |
---|
| 148 | /bin/rm -f $BOSSNODE |
---|
| 149 | # Also clear any cached data that might interfere with rourte construction. |
---|
| 150 | /bin/rm -f /var/emulab/boot/tmcc/ifconfig |
---|
| 151 | |
---|
| 152 | # I remain unclear why ospfd seems screwed up after the resetting of accounts |
---|
| 153 | # and mounts. This seems to fix it, but it's not very satisfying. At this |
---|
| 154 | # point the federated topology is complete, so any problems with routing in a |
---|
| 155 | # partial topology -e.g. failed or partial bridging - that might have confused |
---|
| 156 | # the router should be gone. |
---|
[f3691ff] | 157 | $PKILL ospf |
---|
| 158 | $PKILL gated |
---|
| 159 | # XXX Danger, hack ahead. Apparently our FC6-SMB image and emulab disagree |
---|
| 160 | # about where gated lives. This will alias it. |
---|
| 161 | if [ ! -x /usr/sbin/gated ] ; then |
---|
| 162 | if [ -x /sbin/gated ] ; then |
---|
| 163 | ln /sbin/gated /usr/sbin/gated |
---|
| 164 | fi |
---|
| 165 | fi |
---|
[4abace9] | 166 | /usr/local/etc/emulab/rc/rc.route boot |
---|
| 167 | |
---|
[7c3008e] | 168 | # And restore the ifconfig information because SEER wants it. (SEER pulls this |
---|
| 169 | # from tmcc now |
---|
| 170 | # "$EMUDIR/tmcc" ifconfig > /var/emulab/boot/tmcc/ifconfig |
---|
| 171 | |
---|
| 172 | # SEER feels pain and confusion if times are wrong. This lays a big lick on |
---|
| 173 | # ntp sets the time directly and then restarts it. XXX FreeBSD incantation is |
---|
| 174 | # untested. |
---|
| 175 | |
---|
| 176 | case `uname` in |
---|
| 177 | "FreeBSD") |
---|
| 178 | /etc/rc.d/ntpd stop |
---|
| 179 | /usr/sbin/ntpdate boss |
---|
| 180 | /etc/rc.d/ntpd start |
---|
| 181 | ;; |
---|
| 182 | "Linux") |
---|
| 183 | /etc/rc.d/init.d/ntpd stop |
---|
| 184 | /usr/sbin/ntpdate boss |
---|
| 185 | /etc/rc.d/init.d/ntpd start |
---|
| 186 | ;; |
---|
| 187 | esac |
---|
| 188 | |
---|
[4abace9] | 189 | # Execute any command passed in as a startcmd. This basically daisy chains the |
---|
[7c3008e] | 190 | # startcmd. This needs to become a perl script to have uniform behavior here. |
---|
| 191 | echo "*$1* *$2*" |
---|
[d53dda5] | 192 | if [ ! -z "$1" ]; then |
---|
[7c3008e] | 193 | echo "calling *$1* *$2*" |
---|
| 194 | case `uname` in |
---|
| 195 | "FreeBSD") |
---|
| 196 | su -l "$1" -c "$2" |
---|
| 197 | ;; |
---|
| 198 | "Linux") |
---|
| 199 | su "$1" --command="$2" |
---|
| 200 | ;; |
---|
| 201 | esac |
---|
[d53dda5] | 202 | fi |
---|