Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run processes in new pgroup #723

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/foreman/engine.rb
Expand Up @@ -191,14 +191,14 @@ def kill_children(signal="SIGTERM")
@running.each do |pid, (process, index)|
system "sending #{signal} to #{name_for(pid)} at pid #{pid}"
begin
Process.kill(signal, pid)
Process.kill("-#{signal}", pid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sends the signal to all processes in the group. I still saw leftover processes when the signal was sent only to the parent

rescue Errno::ESRCH, Errno::EPERM
end
end
else
begin
pids = @running.keys.compact
Process.kill signal, *pids unless pids.empty?
Process.kill("-#{signal}", *pids) unless pids.empty?
rescue Errno::ESRCH, Errno::EPERM
end
end
Expand Down
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