From: Andrew DeFaria Date: Tue, 8 Apr 2014 19:34:01 +0000 (-0700) Subject: Merge branch 'master' of /opt/git/clearscm X-Git-Url: https://defaria.com/gitweb/?a=commitdiff_plain;h=1a76436dbd91ded054db928a87255e967bdfd247;hp=e8f2fdadcefb8fa719ed526d037d5f944c9d5e7e;p=clearscm.git Merge branch 'master' of /opt/git/clearscm --- diff --git a/bin/rexec b/bin/rexec index 3dad3ac..7f73760 100755 --- a/bin/rexec +++ b/bin/rexec @@ -193,34 +193,37 @@ sub execute ($$;$) { return ($status, @lines); } # execute -sub parallelize ($%) { - my ($cmd, %machines) = @_; +sub parallelize ($@) { + my ($cmd, @machines) = @_; my $thread_count = 1; - foreach my $host (sort keys %machines) { + foreach (@machines) { + my %system = %$_; + if ($thread_count <= $opts{parallel}) { - debug "Processing $host ($thread_count)"; + debug "Processing $system{name} ($thread_count)"; $thread_count++; if (my $pid = fork) { # In parent process - record this host and its status - $workerNames{$pid} = $host; + display "Putting $system{name} into workerName{$pid}"; + $workerNames{$pid} = $system{host}; } else { # In spawned child... $pid = $$; - debug "Starting process for $host [$pid]"; + debug "Starting process for $system{name} [$pid]"; - $workerNames{$pid} = $host; + $workerNames{$pid} = $system{name}; # Mark currentHost for interrupt (How does this work in the presence # of parallelization?). - $currentHost = $host; + $currentHost = $system{name}; - my ($status, @lines) = execute $cmd, $host, $machines{$host}; + my ($status, @lines) = execute $cmd, $system{name}; - $log = Logger->new (name => $host); + $log = Logger->new (name => $system{name}); $log->log ($_) foreach (@lines); @@ -229,8 +232,16 @@ sub parallelize ($%) { } else { # Wait for somebody to finish; debug "Waiting for somebody to exit..."; + + display "Current status of workerNames:"; + display $_ foreach (keys %workerNames); my $reaped = wait; + if ($workerNames{$reaped}) { + display "workerNames for pid $reaped exists!"; + } else { + display "workerNames for pid $reaped does not exist!"; + } debug "Reaped $workerNames{$reaped} [$reaped] (Status: $?)"; $workerStatuses{$reaped} = $? >> 8 if $reaped != -1; @@ -260,13 +271,15 @@ sub parallelize ($%) { # Gather output... display "Output of all executions"; - foreach my $host (sort keys %machines) { - if (-f "$host.log") { - display "$host:$_" foreach (ReadFile ("$host.log")); + foreach (@machines) { + my %system = %$_; + + if (-f "$system{name}.log") { + display "$system{name}:$_" foreach (ReadFile ("$system{name}.log")); - #unlink "$_host.log"; + unlink "$system{name}.log"; } else { - warning "Unable to find output for $host ($host.log missing)"; + warning "Unable to find output for $system{name} ($system{name}.log missing)"; } # if } # foreach @@ -296,7 +309,9 @@ pod2usage ('No command specified') unless $cmd; my $machines = Clearadm->new; if ($opts{parallel} > 0) { - #parallelize ($cmd, %machines); + my @machines = $machines->SearchSystem ("type='$opts{type}'"); + + parallelize ($cmd, @machines); Stats \%total, $log; exit; } # if