Skip to content

Commit 6970a47

Browse files
committed
Kill multiple matching processes
This commit changes the logic that kills running processes to kill *all* matching processes, not just one. We need this because IBM sucks.
1 parent 63d6ffc commit 6970a47

File tree

1 file changed

+17
-15
lines changed
  • lib/puppet/provider/ibm_impkg

1 file changed

+17
-15
lines changed

lib/puppet/provider/ibm_impkg/imcl.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,31 +100,33 @@ def stopprocs
100100
ps = Facter.value :ps
101101
regex = Regexp.new(resource[:target])
102102
self.debug "Executing '#{ps}' to find processes that match #{resource[:target]}"
103-
pid = nil
103+
pid = []
104104
IO.popen(ps) { |table|
105105
table.each_line { |line|
106106
if regex.match(line)
107107
self.debug "Process matched: #{line}"
108108
ary = line.sub(/^\s+/, '').split(/\s+/)
109-
pid = ary[1]
109+
pid << ary[1]
110110
end
111111
}
112112
}
113113

114114
## If a PID matches, attempt to kill it.
115-
if pid
116-
begin
117-
self.debug "Attempting to kill PID #{pid}"
118-
output = kill pid
119-
rescue Puppet::ExecutionFailure
120-
err = <<-EOF
121-
Could not kill #{self.name}, PID #{pid}.
122-
In order to install/upgrade to specified target: #{resource[:target]},
123-
all related processes need to be stopped.
124-
Output of 'kill #{pid}': #{output}
125-
EOF
126-
127-
@resource.fail Puppet::Error, err, $!
115+
unless pid.empty?
116+
pid.each do |thepid|
117+
begin
118+
self.debug "Attempting to kill PID #{thepid}"
119+
output = kill thepid
120+
rescue Puppet::ExecutionFailure
121+
err = <<-EOF
122+
Could not kill #{self.name}, PID #{thepid}.
123+
In order to install/upgrade to specified target: #{resource[:target]},
124+
all related processes need to be stopped.
125+
Output of 'kill #{thepid}': #{output}
126+
EOF
127+
128+
@resource.fail Puppet::Error, err, $!
129+
end
128130
end
129131
end
130132

0 commit comments

Comments
 (0)