Browse files

Ensure foreman is the process group leader

Foreman should be the process leader before killing processes using
his process group id.

Before that foreman was broken when it was not spawned from a shell.
  • Loading branch information...
1 parent 553ac7f commit 44726e377efe80efee40260fea7280f2f91097f4 @ctrochalakis ctrochalakis committed Dec 27, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/foreman/engine.rb
View
5 lib/foreman/engine.rb
@@ -37,6 +37,9 @@ def initialize(options={})
# Start the processes registered to this +Engine+
#
def start
+ # Make sure foreman is the process group leader.
+ Process.setpgrp unless Foreman.windows?
+
trap("TERM") { puts "SIGTERM received"; terminate_gracefully }
trap("INT") { puts "SIGINT received"; terminate_gracefully }
trap("HUP") { puts "SIGHUP received"; terminate_gracefully } if ::Signal.list.keys.include? 'HUP'
@@ -109,7 +112,7 @@ def killall(signal="SIGTERM")
end
else
begin
- Process.kill "-#{signal}", Process.pid
+ Process.kill "-#{signal}", Process.getpgrp
rescue Errno::ESRCH, Errno::EPERM
end
end

0 comments on commit 44726e3

Please sign in to comment.