source: fedkit/federate.pl @ 2b11a1d

axis_examplecompt_changesinfo-opsversion-3.01version-3.02
Last change on this file since 2b11a1d was 55779d4, checked in by Ted Faber <faber@…>, 14 years ago

Supporting nodes connected by transit networks

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