lib/invoker/commander.rb in invoker-1.0.2 vs lib/invoker/commander.rb in invoker-1.0.3
- old
+ new
@@ -159,19 +159,20 @@
def kill_or_remove_process(pid, signal_to_use, command_label)
process_kill(pid, signal_to_use)
true
rescue Errno::ESRCH
+ Invoker::Logger.puts("Killing process with #{pid} and name #{command_label} failed".color(:red))
remove_worker(command_label, false)
false
end
def process_kill(pid, signal_to_use)
if signal_to_use.to_i == 0
- Process.kill(signal_to_use, pid)
+ Process.kill(signal_to_use, -Process.getpgid(pid))
else
- Process.kill(signal_to_use.to_i, pid)
+ Process.kill(signal_to_use.to_i, -Process.getpgid(pid))
end
end
def select_color
selected_color = LABEL_COLORS.shift()
@@ -201,20 +202,21 @@
def run_command(process_info, write_pipe)
command_label = process_info.label
event_manager.schedule_event(command_label, :exit) { remove_worker(command_label) }
+ spawn_options = {
+ :chdir => process_info.dir || ENV['PWD'], :out => write_pipe, :err => write_pipe,
+ :pgroup => true, :close_others => true, :in => :close
+ }
+
if defined?(Bundler)
Bundler.with_clean_env do
- spawn(process_info.cmd,
- :chdir => process_info.dir || "/", :out => write_pipe, :err => write_pipe
- )
+ spawn(process_info.cmd, spawn_options)
end
else
- spawn(process_info.cmd,
- :chdir => process_info.dir || "/", :out => write_pipe, :err => write_pipe
- )
+ spawn(process_info.cmd, spawn_options)
end
end
def wait_on_pid(command_label,pid)
raise Invoker::Errors::ToomanyOpenConnections if @thread_group.enclosed?
@@ -256,11 +258,12 @@
end
def kill_workers
@workers.each {|key,worker|
begin
- Process.kill("INT", worker.pid)
+ Process.kill("INT", -Process.getpgid(worker.pid))
rescue Errno::ESRCH
+ puts "Error killing #{key}"
end
}
@workers = {}
end
end