From 91dce34f77f64978c35c2bc7c5d8ec91f205a13d Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 7 May 2013 12:16:26 -0400 Subject: [PATCH] Be more graceful when terminating background processes --- rakefiles/helpers.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/rakefiles/helpers.rb b/rakefiles/helpers.rb index cd3d858e44..be5929d805 100644 --- a/rakefiles/helpers.rb +++ b/rakefiles/helpers.rb @@ -37,18 +37,28 @@ def background_process(*command) pgid = Process.getpgid(pid) begin Timeout.timeout(5) do - puts "Terminating process group #{pgid}" - Process.kill(:SIGTERM, -pgid) + puts "Interrupting process group #{pgid}" + Process.kill(:SIGINT, -pgid) puts "Waiting on process group #{pgid}" Process.wait(-pgid) puts "Done waiting on process group #{pgid}" end rescue Timeout::Error - puts "Killing process group #{pgid}" - Process.kill(:SIGKILL, -pgid) - puts "Waiting on process group #{pgid}" - Process.wait(-pgid) - puts "Done waiting on process group #{pgid}" + begin + Timeout.timeout(5) do + puts "Terminating process group #{pgid}" + Process.kill(:SIGTERM, -pgid) + puts "Waiting on process group #{pgid}" + Process.wait(-pgid) + puts "Done waiting on process group #{pgid}" + end + rescue Timeout::Error + puts "Killing process group #{pgid}" + Process.kill(:SIGKILL, -pgid) + puts "Waiting on process group #{pgid}" + Process.wait(-pgid) + puts "Done waiting on process group #{pgid}" + end end end end