source: fedkit/federate.pl @ 6d985c0

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

Replacement federation script that undertsands services

  • Property mode set to 100644
File size: 3.4 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
82if ($services{'userconfig'}) {
83    $tmcc_p = new IO::Pipe() || die "Can't open pipe for accounts:$!\n";
84    my $old_accounts = new IO::File(">$local_config_dir/old_accts") || 
85        die "Can't open $local_config_dir/old_accts: $!\n";
86
87    $tmcc_p->reader("$TMCC -b accounts");
88    while (<$tmcc_p>) {
89        print $old_accounts $_;
90    }
91    $tmcc_p->close();
92    $old_accounts->close();
93    print("Updating accounts");
94    system("/usr/local/federation/bin/rc.fedaccounts");
95}
96
97if ($services{'SMB'}) {
98    if ($uname =~ /FreeBSD/ ) {
99        system("umount -A -f -t nfs,smbfs,cifs");
100        # Restart ntp
101        system("/etc/rc.d/ntpd stop; /usr/sbin/ntpdate boss; " . 
102            "/etc/rc.d/ntpd start;");
103                                                   
104    }
105    elsif ($uname =~ /Linux/ ) {
106        # Pass individual filestems to Linux umount.  No -A.
107        my $mtab = new IO::File("/etc/mtab") || die "Can't open /etc/mtab:$1\n";
108        while (<$mtab>) {
109            chomp;
110            my @F = split($_);
111            next unless $F[2] =~ /(nfs|cifs|smbfs)/;
112            system("umount -f $F[1]");
113        }
114        # restart ntp
115        system("/etc/rc.d/init.d/ntpd stop; /usr/sbin/ntpdate boss; ". 
116            "/etc/rc.d/init.d/ntpd start");
117    }
118
119    print "Waiting for SMB server\n";
120    gateway_lib::wait_for_port($gateway, 139, 60*60) || 
121        die "SMB server never came up\n";
122    print "Mounting via SMB\n";
123    system("$perl /usr/local/federation/bin/$smbmount $smbshare $gateway " . 
124        "$smbuser $smbproject");
125}
126
127# startcmd
128if ($ARGV[0] && $ARGV[1]) {
129    if ($uname =~ /FreeBSD/) {
130        system("su -l \"$ARGV[0]\" -c \"$ARGV[1]\"");
131    }
132    elsif ($uname =~ /Linux/) {
133        system("su \"$ARGV[0]\" --command \"$ARGV[1]\"");
134    }
135}
136exit(0);
Note: See TracBrowser for help on using the repository browser.