Skip to content

Commit

Permalink
Run processes in new pgroup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
David Harsha committed Oct 30, 2018
1 parent c0b178c commit d0be807
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/foreman/process.rb
Expand Up @@ -49,9 +49,10 @@ def run(options={})
env = @options[:env].merge(options[:env] || {})
output = options[:output] || $stdout
runner = "#{Foreman.runner}".shellescape

pgroup = Foreman.windows? ? :new_pgroup : :pgroup

Dir.chdir(cwd) do
Process.spawn env, expanded_command(env), :out => output, :err => output
Process.spawn env, expanded_command(env), :out => output, :err => output, pgroup => true
end
end

Expand Down

0 comments on commit d0be807

Please sign in to comment.