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:
61: go = true
62: while go
63:
64:
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:
73: begin
74: pid = Process.wait
75:
76: if host = @children[pid]
77:
78:
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:
87:
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