diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index 05ea01a..5b96b91 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -99,7 +99,20 @@ class Foreman::Engine # @param [String] signal The signal to send to each process # def killall(signal="SIGTERM") - Process.kill "-#{signal}", Process.pid + if Foreman.windows? + @running.each do |pid, (process, index)| + system "sending #{signal} to #{name_for(pid)} at pid #{pid}" + begin + Process.kill(signal, pid) + rescue Errno::ESRCH, Errno::EPERM + end + end + else + begin + Process.kill "-#{signal}", Process.pid + rescue Errno::ESRCH, Errno::EPERM + end + end end # Get the process formation @@ -282,8 +295,13 @@ private def terminate_gracefully return if @terminating @terminating = true - system "sending SIGTERM to all processes" - killall "SIGTERM" + if Foreman.windows? + system "sending SIGKILL to all processes" + killall "SIGKILL" + else + system "sending SIGTERM to all processes" + killall "SIGTERM" + end Timeout.timeout(5) do watch_for_termination while @running.length > 0 end diff --git a/lib/foreman/engine/cli.rb b/lib/foreman/engine/cli.rb index 6c44f43..db02056 100644 --- a/lib/foreman/engine/cli.rb +++ b/lib/foreman/engine/cli.rb @@ -31,6 +31,7 @@ class Foreman::Engine::CLI < Foreman::Engine def color? return true if @@color_force + return true if Foreman.windows? return false unless self.respond_to?(:isatty) self.isatty && ENV["TERM"] end @@ -49,11 +50,12 @@ class Foreman::Engine::CLI < Foreman::Engine def startup @colors = map_colors proctitle "foreman: master" + require "win32console" if Foreman.windows? + Color.enable($stdout, options[:color]) unless $stdout.respond_to?(:color?) end def output(name, data) data.to_s.chomp.split("\n").each do |message| - Color.enable($stdout, options[:color]) unless $stdout.respond_to?(:color?) output = "" output += $stdout.color(@colors[name.split(".").first].to_sym) output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | " diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index d208c3a..fe5c944 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -36,7 +36,11 @@ class Foreman::Process if Foreman.windows? Dir.chdir(cwd) do - Process.spawn env, command, :out => output, :err => output + expanded_command = command.dup + env.each do |key, val| + expanded_command.gsub!("$#{key}", val) + end + Process.spawn env, expanded_command, :out => output, :err => output end elsif Foreman.jruby? Dir.chdir(cwd) do @@ -64,7 +68,11 @@ class Foreman::Process # @param [String] signal The signal to send # def kill(signal) - pid && Process.kill("-#{signal}", pid) + if Foreman.windows? + pid && Process.kill(signal, pid) + else + pid && Process.kill("-#{signal}", pid) + end rescue Errno::ESRCH false end