plabhttpd.in 2.25 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2003-2007 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# All rights reserved.
#

#
# Simple little script to start up thttpd on planetlab nodes - it actually
# restarts the server gracefully, so that any downloads already going on will
# get to complete
#

use lib '@prefix@/lib';
use libdb;

#
# Username that we'll use to ssh into planetlab nodes
#
20
my $PLAB_USER = "utah_svc_slice";
21 22 23 24 25 26

#
# Script to run on the plab nodes to start the webserver
#
my $THTTPD_START = "netbed_files/sbin/thttpd.restart";

27 28 29 30 31
#
# max parallelization
#
my $MAX_CHILDREN = 10;

32 33 34 35 36
#
# SSH command
#
my $SSH = "ssh -q -oBatchMode=yes -oStrictHostKeyChecking=no -l $PLAB_USER";

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
my @nodes = ();

if (@ARGV) {
    @nodes = @ARGV;
}

if (!scalar(@nodes)) {
    #
    # Get a list of planetlab nodes that are up
    #
    my $query_result = 
	DBQueryFatal("SELECT n.node_id FROM nodes as n " .
		     "LEFT JOIN node_status AS s ON n.node_id=s.node_id " .
		     "LEFT JOIN reserved AS r ON n.node_id = r.node_id " .
		     "WHERE n.type=\"pcplabphys\" AND s.status=\"up\" AND " .
		     "!(r.pid=\"" . NODEDEAD_PID .
		     "\" AND r.eid=\"" . NODEDEAD_EID .  "\") " . 
		     "order by n.node_id");

    while (my ($node) = $query_result->fetchrow()) {
	push @nodes, $node;
    }
}

61
#
62
# Run up to $max_children rsyncs at a time
63
#
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
my $current_children = 0;
my @failed = ();
my %children = ();
while (@nodes || $current_children) {
    if (($current_children < $MAX_CHILDREN) && @nodes) {
	#
	# If we have room for another child, start one up
	#
        my $node = pop @nodes;
        if (my $pid = fork()) {
            $current_children++;
            $children{$pid} = $node;
        } else {
            print "Starting up webserver on $node\n\n";
            exec "$SSH $node $THTTPD_START";
        }
    } else {
	#
	# Wait for a child to die, and see if it failed
	#
        my $childpid = wait();
        if ($childpid < 0) {
            die "Bad return value from wait(): $childpid\n";
        }
        if ($children{$childpid}) {
            $current_children--;
            if ($?) {
                push @failed, $children{$childpid};
            }
        }
    }
}
96

97 98 99
if (@failed) {
    print "Some nodes failed: \n";
    print map {"$_\n"} @failed;
100
}
101 102

exit scalar @failed;