handle windows

This commit is contained in:
David Dollar
2012-07-11 16:02:07 -04:00
parent 9849f4558a
commit cefd4e351e
3 changed files with 34 additions and 6 deletions

View File

@@ -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

View File

@@ -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)} | "

View File

@@ -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