source: fedkit/federate.sh @ a2da110

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

Support for this as a real fedkit. Loads using fedd and establishes connectivity

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