Skip to content

Commit 7d6f35a

Browse files
author
David Harsha
committed
Run processes in new pgroup
Some processes are getting orphaned when running Foreman with JRuby. Creating a new pgroup allows them all to be killed together. I believe the issue is related to how JRuby handles `Dir.chdir` by creating a shell process: `sh -c 'cd /chdir/target; ${command}'`. That causes a second process to be created that won't get cleaned up by killing the parent.
1 parent c0b178c commit 7d6f35a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/foreman/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def kill_children(signal="SIGTERM")
198198
else
199199
begin
200200
pids = @running.keys.compact
201-
Process.kill signal, *pids unless pids.empty?
201+
Process.kill("-#{signal}", *pids) unless pids.empty?
202202
rescue Errno::ESRCH, Errno::EPERM
203203
end
204204
end

lib/foreman/process.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ def run(options={})
4949
env = @options[:env].merge(options[:env] || {})
5050
output = options[:output] || $stdout
5151
runner = "#{Foreman.runner}".shellescape
52-
52+
pgroup = Foreman.windows? ? :new_pgroup : :pgroup
53+
5354
Dir.chdir(cwd) do
54-
Process.spawn env, expanded_command(env), :out => output, :err => output
55+
Process.spawn env, expanded_command(env), :out => output, :err => output, pgroup => true
5556
end
5657
end
5758

0 commit comments

Comments
 (0)