From 38aecff886504bdfaf3fecac58ef271c66e7fad3 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Tue, 10 Apr 2012 20:21:43 -0700 Subject: [PATCH] When executing #stop(nil), all processes should be sent the signal --- lib/foreman/engine.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index a665535..7ca47e2 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -44,7 +44,14 @@ class Foreman::Engine def stop(name, signal='SIGTERM') running_processes.each do |pid, process| - next unless process.name.start_with? name + unless name.nil? + # Comparing against process.entry.name instead of process.name to + # make sure we match the process name exactly for any/all + # concurrently running processes by this name + next unless process.entry.name == name + else + info "sending #{signal} to all processes" + end process.kill signal process = running_processes.delete(pid) @@ -89,18 +96,11 @@ private ###################################################################### def terminate_gracefully return if @terminating @terminating = true - info "sending SIGTERM to all processes" Timeout.timeout(5) do - running_processes.each do |pid, process| - stop(process.name) - end + stop(nil) end rescue Timeout::Error - info "sending SIGKILL to all processes" - running_process.each do |pid, process| - info "sending #{signal} to pid #{pid}" - stop(process.name, 'SIGKILL') - end + stop(nil, 'SIGKILL') rescue Errno::ECHILD end