source: fedkit/federate.pl @ 8cce763

axis_examplecompt_changesinfo-opsversion-3.01version-3.02
Last change on this file since 8cce763 was dc803a7, checked in by Ted Faber <faber@…>, 15 years ago

Set up all routing daemons from the fedkit and note interfaces we've added in a way that SEER's federated testbed will grok them.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1#! /usr/bin/perl
2
3
4use strict;
5
6use Getopt::Long;
7
8use IO::File;
9use IO::Pipe;
10use File::Copy;
11
12use Net::hostent;
13use Socket;
14
15use gateway_lib;
16
17chdir("/tmp");
18
19my $TMCC = "/usr/local/etc/emulab/tmcc";
20my $RC_ROUTE = "/usr/local/etc/emulab/rc/rc.route";
21my $tmcc_p = new IO::Pipe() || die "Can't open pipe: $!\n";
22my $shared_config_dir;
23my $local_config_dir = "/usr/local/federation/etc";
24my %services;
25my $perl;
26
27my $gateway;
28my $smbshare = "USERS";
29my $smbuser;
30my $smbproject;
31my $exp;
32my $proj;
33my $install_smb;
34my $smb_type = 'cifs';
35chomp (my $uname = `uname`);
36my $smbmount = "smbmount.$uname.pl";
37
38GetOptions("install_samba" => \$install_smb);
39
40# find perl
41for my $p ("/usr/bin/perl", "/usr/local/bin/perl") {
42    if ( -x $p ) {
43        $perl = $p;
44        last;
45    }
46}
47$perl = "perl" unless $perl;
48
49if ($install_smb) {
50    # fix yum.conf
51    copy("/etc/yum.conf", "/etc/yum.conf.bak");
52    my $from = new IO::File("/etc/yum.conf.bak");
53    my $to = new IO::File(">/etc/yum.conf");
54    while (<$from>) {
55        s/download.fedoralegacy.org/fedoralegacy.lsu.edu/g;
56        print $to $_;
57    }
58    $from->close();
59    $to->close();
60    # Now, samba.  Because of the python dance on PG, we need to call python2.2
61    # explicitly
62    system('/usr/bin/python2.2 /usr/bin/yum -y install samba-client');
63    # These tools expect the fstab to include smbfs instead
64    $smb_type = 'smbfs';
65}
66
67if (!-e "$local_config_dir/client.conf" ) {
68    $tmcc_p->reader("$TMCC -b status");
69    while (<$tmcc_p>) {
70        /ALLOCATED=([^\/]+)\/(\S+)/ && do {
71            ($proj, $exp) = ($1, $2);
72            $shared_config_dir = "/proj/$proj/exp/$exp/tmp";
73            last;
74        };
75    }
76    $tmcc_p->close();
77
78    mkdir($local_config_dir);
79
80    foreach my $fn ("seer.conf", "client.conf", "userconf", "hosts") {
81        copy("$shared_config_dir/$fn", $local_config_dir )
82            if -e "$shared_config_dir/$fn";
83    }
84}
85
86my $client = new IO::File("$local_config_dir/client.conf");
87while (<$client>) {
88    chomp;
89    /ControlGateway:\s+(.*)/i && do { $gateway = $1; };
90    /SMBShare:\s+(.*)/i && do { $smbshare = $1; };
91    /ProjectUser:\s+(.*)/i && do { $smbuser = $1; };
92    /ProjectName:\s+(.*)/i && do { $smbproject = $1; };
93    /Service:\s+(.*)/i && do { $services{$1}++;};
94}
95$client->close();
96# Create the /etc/hosts file
97my $hosts = new IO::File("/etc/hosts") || die "Can't open /etc/hosts:$!\n";
98my $new_hosts = new IO::File(">/tmp/hosts") || die "Can't open /tmp/hosts:$!\n";
99my $config_hosts = new IO::File("$local_config_dir/hosts") || 
100    die "Can't open $local_config_dir/hosts: $!\n";
101my $has_control = 0;
102
103while (<$hosts>) {
104    /^127\.0\.0\.1/ && do { print $new_hosts $_; };
105    /control\./ && $has_control++;
106}
107$hosts->close();
108while (<$config_hosts>) {
109    print $new_hosts $_;
110}
111$config_hosts->close();
112
113# If seer is enabled and no local control node in play, alias the gateway to be
114# control
115if ($services{'seer'} && !$has_control ) {
116    if ( my $hent = gethostbyname($gateway) ) {
117        my $gwip = inet_ntoa($hent->addr_list->[0]);
118
119        print $new_hosts "\n$gwip\tcontrol.$exp.$proj\n";
120    }
121}
122$new_hosts->close();
123copy("/tmp/hosts", "/etc/hosts");
124
125
126# If there are tunnelip interfaces to bring up, bring 'em up.  Record any such
127# interfaces in /usr/local/federation/interfaces, so SEER can find them later.
128system("$perl -I/usr/local/federation/lib " . 
129    "/usr/local/federation/bin/config_from_tunnelip.pl " . 
130    "--record=/usr/local/federation/etc/interfaces");
131
132if ($uname =~ /Linux/ ) {
133    system("$perl /usr/local/federation/bin/gated_routing.pl")
134        if -r "/usr/local/federation/bin/gated_routing.pl";
135}
136elsif ($uname =~/FreeBSD/ ) {
137    # FreeBSD needs to have ospfs installed and a router config created and
138    # run.
139    system("$perl /usr/local/federation/bin/ospf_routing.pl")
140        if -r "/usr/local/federation/bin/ospf_routing.pl";
141}
142
143
144if ($services{'userconfig'}) {
145    if (!-e "$local_config_dir/old_accts") {
146        $tmcc_p = new IO::Pipe() || die "Can't open pipe for accounts:$!\n";
147        my $old_accounts = new IO::File(">$local_config_dir/old_accts") || 
148            die "Can't open $local_config_dir/old_accts: $!\n";
149
150        $tmcc_p->reader("$TMCC -b accounts");
151        while (<$tmcc_p>) {
152            print $old_accounts $_;
153        }
154        $tmcc_p->close();
155        $old_accounts->close();
156    }
157    print("Updating accounts");
158    system("/usr/local/federation/bin/rc.fedaccounts");
159}
160
161if ($services{'SMB'}) {
162    if ($uname =~ /FreeBSD/ ) {
163        system("umount -A -f -t nfs,smbfs,cifs");
164        $smb_type = "smbfs";
165    }
166    elsif ($uname =~ /Linux/ ) {
167        # Pass individual filestems to Linux umount.  No -A.
168        my $mtab = new IO::File("/etc/mtab") || die "Can't open /etc/mtab:$!\n";
169        while (<$mtab>) {
170            chomp;
171            my @F = split($_);
172            next unless $F[2] =~ /(nfs|cifs|smbfs)/;
173            system("umount -f $F[1]");
174        }
175    }
176
177    print "Waiting for SMB server\n";
178    gateway_lib::wait_for_port($gateway, 139, 60*60) || 
179        die "SMB server never came up\n";
180    print "Mounting via SMB\n";
181    system("$perl /usr/local/federation/bin/$smbmount $smbshare $gateway " . 
182        "$smbuser $smbproject $smb_type");
183}
184
185if ($uname =~ /FreeBSD/ ) {
186    # Restart ntp
187    system("/etc/rc.d/ntpd stop; /usr/sbin/ntpdate boss; " . 
188        "/etc/rc.d/ntpd start;");
189                                               
190}
191elsif ($uname =~ /Linux/ ) {
192    # restart ntp
193    system("/etc/rc.d/init.d/ntpd stop; /usr/sbin/ntpdate boss; ". 
194        "/etc/rc.d/init.d/ntpd start");
195}
196
197# startcmd
198if ($ARGV[0] && $ARGV[1]) {
199    if ($uname =~ /FreeBSD/) {
200        system("su -l \"$ARGV[0]\" -c \"$ARGV[1]\"");
201    }
202    elsif ($uname =~ /Linux/) {
203        system("su \"$ARGV[0]\" --command \"$ARGV[1]\"");
204    }
205}
206exit(0);
Note: See TracBrowser for help on using the repository browser.