runbgmon 1.84 KB
Newer Older
1
#!/usr/bin/perl
Dan Gebhardt's avatar
Dan Gebhardt committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# All rights reserved.
#
7

8
use Getopt::Std;
9

10
my $expt;
11
my $iperfport = 5002;
12

13 14 15 16 17 18 19
sub usage {
	warn "Usage: $0 [-e pid/eid] <bin_path>\n";
	return 1;
}

my %opt = ();

20
if (!getopts("e:i:", \%opt)) {
21 22 23
    exit &usage;
}

24 25
if ($opt{i}) { $iperfport = $opt{i}; }

26 27 28 29 30 31 32 33 34 35 36
if ($opt{e}) { 
    $expt = $opt{e}; 
} else {
    open(NID, "</var/emulab/boot/nickname")
        or die "Can't open nodeid file!";
    my $nid = <NID>;
    close(NID);
    chomp $nid;
    my (undef, $eid, $pid) = split /\./, $nid;
    $expt = "$pid/$eid";
}
37 38

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

42
my $path = $ARGV[0];
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
# Find out what version of Fedora Core this node is running
open(FR, "</etc/fedora-release")
        or die "Unable to open fedora-release file: $!\n";
my $release_string = <FR>;
my $fc_version;
my $os_string;
if ($release_string =~ /Fedora Core release (\d+)/) {
    $fc_version = "$1";
    $os_string = "FC$1";
} else {
    die "Unable to determine Fedora release version from '$release_string'\n";
}

print "Running on OS $os_string\n";

# Symlink each binary to the appropriate version
foreach my $bin ("iperf", "iperfd", "fping") {
    my $destbin = "$path/$bin";
    my $sourcebin = "$path/$bin-$os_string";
    if (-e $destbin) {
        unlink $destbin or die "Unable to remove old $destbin: $!\n";
    }
    if (!-e $sourcebin) {
        die "Missing required binary: $sourcebin\n";
    }
    if (!link($sourcebin, $destbin)) {
        die "Unable to link $sourcebin to $destbin\n";
    }
}

Dan Gebhardt's avatar
Dan Gebhardt committed
74 75
#system "sudo perl $path/bgmon.pl -e $expt -i $iperfport -d $path/ >/tmp/bgmon.log&";
system "sudo perl -I$path $path/bgmon.pl -e $expt -i $iperfport -d $path/&";
76 77
system "sudo rm $path/iperfd.out $path/iperfd.err";
system "sudo $path/iperfd -s -p $iperfport >& $path/iperfd.err > $path/iperfd.out &";
78

79
exit 0;