source: fedkit/federate.sh @ b09f346

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since b09f346 was b09f346, checked in by Ted Faber <faber@…>, 16 years ago

a little defensive programming

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