From b561555f3a11cdcd96ce5f158bd20189be36eafa Mon Sep 17 00:00:00 2001 From: brainopia Date: Sun, 8 Jan 2012 09:42:51 +0700 Subject: [PATCH] Fix for double fork --- lib/foreman/engine.rb | 7 +++++++ lib/foreman/process.rb | 2 ++ 2 files changed, 9 insertions(+) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index c65a5a5..7fa6fd3 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -72,10 +72,17 @@ private ###################################################################### def kill_all(signal="SIGTERM") running_processes.each do |pid, process| info "sending #{signal} to pid #{pid}" + kill(signal, -pid) or kill(signal, pid) Process.kill(signal, pid) rescue Errno::ESRCH end end + def kill(signal, pid) + Process.kill signal, pid + rescue Errno::ESRCH + false + end + def terminate_gracefully info "sending SIGTERM to all processes" kill_all "SIGTERM" diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 06f79f6..e570719 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -30,11 +30,13 @@ private def fork_with_io(command) reader, writer = IO.pipe pid = fork do + Process.setpgrp trap("INT", "IGNORE") $stdout.reopen writer reader.close exec Foreman.runner, replace_command_env(command) end + Process.detach pid [ reader, pid ] end