sddeploy.in 2.78 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
7

8 9 10 11 12 13
#
# Confiigure variables
#
my $CLIENT_BINDIR = "@CLIENT_BINDIR@";
my $CLIENT_ETCDIR = "@CLIENT_ETCDIR@";

14
use lib '@prefix@/lib';
15 16 17 18 19 20 21

use libdb;
use English;
use Getopt::Long;
use strict;

sub usage() {
22
    print "Usage: $0 [-a] | [-e <pid> <eid>] | [vnode ...]\n";
23 24 25 26 27 28
}

my %opts = ();
my $pid;
my $eid;
my @nodes = ();
29
my @failed = ();
30 31 32 33 34 35 36

if (@ARGV < 1) {
    exit &usage;
}

my $linpath = "~kwebb/src/testbed/sensors/slothd/linux/slothd";
my $fbsdpath = "~kwebb/src/testbed/sensors/slothd/fbsd/slothd";
37 38
my $linrcpath = "~kwebb/src/testbed/tmcd/common/rc.testbed";
my $fbsdrcpath = "~kwebb/src/testbed/tmcd/common/rc.testbed";
39 40 41 42

my $SSH = "sudo ssh -q";
my $SCP = "sudo scp -q -o Loglevel=QUIET";

43
GetOptions(\%opts,'h','f=s','e=s','a');
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
if ($opts{"f"}) {
    open(NODEFILE, "<$opts{'f'}");
    while (<NODEFILE>) {
        chomp;
        push @nodes, $_;
    }
}

elsif ($opts{"a"}) {
    my $qres = DBQuery("select a.node_id from reserved as a "
                       . "left join nodes as b "
                       . "on a.node_id = b.node_id "
                       . "where b.type = 'pc850' or b.type = 'pc600'");
    if ($qres) {
        while(my @row = $qres->fetchrow_array()) {
            push @nodes, $row[0];
        }
    }
}

elsif ($opts{"e"}) {
66 67 68 69 70
    $pid = $opts{"e"};
    $eid = shift;
    @nodes = ExpNodes($pid, $eid);
    print "pid: $pid\n";
    print "eid: $eid\n";
71 72 73
} 

else {
74 75 76 77 78 79 80
    @nodes = @ARGV;
}

print "Installing on the following nodes: @nodes\n";

my $j;
foreach $j (@nodes) {
81 82 83 84 85 86 87
    if (InstallSlothd($j)) {
        push @failed, $j;
    }
}

if (@failed) {
    print "failed nodes: @failed\n\n";
88 89
}

90 91
exit 0;

92 93
sub InstallSlothd($) {
    my $node = shift;
94
    my $nodeos = "";
95 96
    
    print "Executing for $node ...\n";
97 98 99 100 101 102 103
    print "pinging node..\n";
    `ping -q -c 2 $node > /dev/null`;
    if ($?) {
        print "host down.. skipping.\n";
        return 1;
    }

104 105
    $nodeos = `$SSH $node uname -s`;
    
106
    if ($nodeos =~ /linux/i) {
107
        print "Node type is linux\n";
108 109 110
        print "stopping slothd on $node\n";
        `$SSH $node killall slothd`;
        sleep 1;
111 112
        `$SCP $linpath $node:$CLIENT_BINDIR`;
        `$SCP $linrcpath $node:$CLIENT_BINDIR`;
113
    }
114
    elsif ($nodeos =~ /freebsd/i) {
115
        print "Node type is FreeBSD\n";
116 117 118
        print "stopping slothd on $node\n";
        `$SSH $node killall slothd`;
        sleep 1;
119 120
        `$SCP $fbsdpath $node:$CLIENT_BINDIR`;
        `$SCP $fbsdrcpath $node:$CLIENT_BINDIR`;    
121
    }
122 123 124 125 126
    else {
        print "Unknown node OS: $nodeos: not deploying.\n";
        return 1;
    }

127
    print "starting slothd on $node\n";
128
    `$SSH $node $CLIENT_BINDIR/slothd`;
129 130 131 132
    if ($?) {
        return 1;
    }
    return 0;
133 134 135
}

exit 0;