# File lib/puppet/application/kick.rb, line 50
 50:   def main
 51:     require 'puppet/network/client'
 52: 
 53:     Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not be available" unless Puppet.features.ldap?
 54:     require 'puppet/util/ldap/connection'
 55: 
 56:     todo = @hosts.dup
 57: 
 58:     failures = []
 59: 
 60:     # Now do the actual work
 61:     go = true
 62:     while go
 63:       # If we don't have enough children in process and we still have hosts left to
 64:       # do, then do the next host.
 65:       if @children.length < options[:parallel] and ! todo.empty?
 66:         host = todo.shift
 67:         pid = fork do
 68:           run_for_host(host)
 69:         end
 70:         @children[pid] = host
 71:       else
 72:         # Else, see if we can reap a process.
 73:         begin
 74:           pid = Process.wait
 75: 
 76:           if host = @children[pid]
 77:             # Remove our host from the list of children, so the parallelization
 78:             # continues working.
 79:             @children.delete(pid)
 80:             failures << host if $CHILD_STATUS.exitstatus != 0
 81:             print "#{host} finished with exit code #{$CHILD_STATUS.exitstatus}\n"
 82:           else
 83:             $stderr.puts "Could not find host for PID #{pid} with status #{$CHILD_STATUS.exitstatus}"
 84:           end
 85:         rescue Errno::ECHILD
 86:           # There are no children left, so just exit unless there are still
 87:           # children left to do.
 88:           next unless todo.empty?
 89: 
 90:           if failures.empty?
 91:             puts "Finished"
 92:             exit(0)
 93:           else
 94:             puts "Failed: #{failures.join(", ")}"
 95:             exit(3)
 96:           end
 97:         end
 98:       end
 99:     end
100:   end