source: fedkit/federate.pl @ 7dc855c

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

I feel so dirty.

The FC6-SMB image has a misplaced gated in that Emulab thinks it should be
somewhere else and dynamic routing fails to come up. Sigh. This little hack
symlinks gated into the right place and restarts the router.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1#! /usr/bin/perl
2
3
4use strict;
5
6use IO::File;
7use IO::Pipe;
8use File::Copy;
9
10use gateway_lib;
11
12chdir("/tmp");
13
14my $TMCC = "/usr/local/etc/emulab/tmcc";
15my $RC_ROUTE = "/usr/local/etc/emulab/rc/rc.route";
16my $tmcc_p = new IO::Pipe() || die "Can't open pipe: $!\n";
17my $shared_config_dir;
18my $local_config_dir = "/usr/local/federation/etc";
19my %services;
20my $perl;
21
22my $gateway;
23my $smbshare = "USERS";
24my $smbuser;
25my $smbproject;
26chomp (my $uname = `uname`);
27my $smbmount = "smbmount.$uname.pl";
28
29# find perl
30for my $p ("/usr/bin/perl", "/usr/local/bin/perl") {
31    if ( -x $p ) {
32        $perl = $p;
33        last;
34    }
35}
36$perl = "perl" unless $perl;
37
38
39$tmcc_p->reader("$TMCC -b status");
40while (<$tmcc_p>) {
41    /ALLOCATED=([^\/]+)\/(\S+)/ && do {
42        $shared_config_dir = "/proj/$1/exp/$2/tmp";
43        last;
44    };
45}
46$tmcc_p->close();
47
48mkdir($local_config_dir);
49
50foreach my $fn ("seer.conf", "client.conf", "userconf") {
51    copy("$shared_config_dir/$fn", $local_config_dir )
52        if -e "$shared_config_dir/$fn";
53}
54
55my $client = new IO::File("$local_config_dir/client.conf");
56while (<$client>) {
57    chomp;
58    /ControlGateway:\s+(.*)/i && do { $gateway = $1; };
59    /SMBShare:\s+(.*)/i && do { $smbshare = $1; };
60    /ProjectUser:\s+(.*)/i && do { $smbuser = $1; };
61    /ProjectName:\s+(.*)/i && do { $smbproject = $1; };
62    /Service:\s+(.*)/i && do { $services{$1}++;};
63}
64$client->close();
65# Create the /etc/hosts file
66my $hosts = new IO::File("/etc/hosts") || die "Can't open /etc/hosts:$!\n";
67my $new_hosts = new IO::File(">/tmp/hosts") || die "Can't open /tmp/hosts:$!\n";
68my $config_hosts = new IO::File("$shared_config_dir/hosts") || 
69    die "Can't open $shared_config_dir/hosts: $!\n";
70
71while (<$hosts>) {
72    /^127\.0\.0\.1/ && do { print $new_hosts $_; };
73}
74$hosts->close();
75while (<$config_hosts>) {
76    print $new_hosts $_;
77}
78$config_hosts->close();
79$new_hosts->close();
80copy("/tmp/hosts", "/etc/hosts");
81
82# Ick.  at least one of our images has gated in the wrong place (sigh).  If
83# so, fix it and restart routing. 
84if (!-x "/usr/sbin/gated" && -x "/sbin/gated" ) {
85    print "Linking to /sbin/gated and starting routing\n";
86    symlink("/sbin/gated", "/usr/sbin/gated");
87    system("$RC_ROUTE boot") if -x $RC_ROUTE;
88}
89
90# If there are tunnelip interfaces to bring up, bring 'em
91system("$perl -I/usr/local/federation/lib " . 
92    "/usr/local/federation/bin/config_from_tunnelip.pl");
93
94
95if ($services{'userconfig'}) {
96    $tmcc_p = new IO::Pipe() || die "Can't open pipe for accounts:$!\n";
97    my $old_accounts = new IO::File(">$local_config_dir/old_accts") || 
98        die "Can't open $local_config_dir/old_accts: $!\n";
99
100    $tmcc_p->reader("$TMCC -b accounts");
101    while (<$tmcc_p>) {
102        print $old_accounts $_;
103    }
104    $tmcc_p->close();
105    $old_accounts->close();
106    print("Updating accounts");
107    system("/usr/local/federation/bin/rc.fedaccounts");
108}
109
110if ($services{'SMB'}) {
111    if ($uname =~ /FreeBSD/ ) {
112        system("umount -A -f -t nfs,smbfs,cifs");
113        # Restart ntp
114        system("/etc/rc.d/ntpd stop; /usr/sbin/ntpdate boss; " . 
115            "/etc/rc.d/ntpd start;");
116                                                   
117    }
118    elsif ($uname =~ /Linux/ ) {
119        # Pass individual filestems to Linux umount.  No -A.
120        my $mtab = new IO::File("/etc/mtab") || die "Can't open /etc/mtab:$1\n";
121        while (<$mtab>) {
122            chomp;
123            my @F = split($_);
124            next unless $F[2] =~ /(nfs|cifs|smbfs)/;
125            system("umount -f $F[1]");
126        }
127        # restart ntp
128        system("/etc/rc.d/init.d/ntpd stop; /usr/sbin/ntpdate boss; ". 
129            "/etc/rc.d/init.d/ntpd start");
130    }
131
132    print "Waiting for SMB server\n";
133    gateway_lib::wait_for_port($gateway, 139, 60*60) || 
134        die "SMB server never came up\n";
135    print "Mounting via SMB\n";
136    system("$perl /usr/local/federation/bin/$smbmount $smbshare $gateway " . 
137        "$smbuser $smbproject");
138}
139
140# startcmd
141if ($ARGV[0] && $ARGV[1]) {
142    if ($uname =~ /FreeBSD/) {
143        system("su -l \"$ARGV[0]\" -c \"$ARGV[1]\"");
144    }
145    elsif ($uname =~ /Linux/) {
146        system("su \"$ARGV[0]\" --command \"$ARGV[1]\"");
147    }
148}
149exit(0);
Note: See TracBrowser for help on using the repository browser.