Fix for double fork

This commit is contained in:
brainopia
2012-01-08 09:42:51 +07:00
parent baa7b7685c
commit b561555f3a
2 changed files with 9 additions and 0 deletions
+7
View File
@@ -72,10 +72,17 @@ private ######################################################################
def kill_all(signal="SIGTERM") def kill_all(signal="SIGTERM")
running_processes.each do |pid, process| running_processes.each do |pid, process|
info "sending #{signal} to pid #{pid}" info "sending #{signal} to pid #{pid}"
kill(signal, -pid) or kill(signal, pid)
Process.kill(signal, pid) rescue Errno::ESRCH Process.kill(signal, pid) rescue Errno::ESRCH
end end
end end
def kill(signal, pid)
Process.kill signal, pid
rescue Errno::ESRCH
false
end
def terminate_gracefully def terminate_gracefully
info "sending SIGTERM to all processes" info "sending SIGTERM to all processes"
kill_all "SIGTERM" kill_all "SIGTERM"
+2
View File
@@ -30,11 +30,13 @@ private
def fork_with_io(command) def fork_with_io(command)
reader, writer = IO.pipe reader, writer = IO.pipe
pid = fork do pid = fork do
Process.setpgrp
trap("INT", "IGNORE") trap("INT", "IGNORE")
$stdout.reopen writer $stdout.reopen writer
reader.close reader.close
exec Foreman.runner, replace_command_env(command) exec Foreman.runner, replace_command_env(command)
end end
Process.detach pid
[ reader, pid ] [ reader, pid ]
end end