Skip to content

Commit

Permalink
Fix for double fork
Browse files Browse the repository at this point in the history
  • Loading branch information
brainopia committed Jan 8, 2012
1 parent baa7b76 commit b561555
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/foreman/engine.rb
Expand Up @@ -72,10 +72,17 @@ def base_port
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"
Expand Down
2 changes: 2 additions & 0 deletions lib/foreman/process.rb
Expand Up @@ -30,11 +30,13 @@ def name
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

Expand Down

0 comments on commit b561555

Please sign in to comment.