This commit is contained in:
David Dollar
2011-12-08 17:53:13 -08:00
parent c9411cd2b1
commit 5436b68cf1
13 changed files with 72 additions and 79 deletions
+19 -12
View File
@@ -5,24 +5,18 @@ class Foreman::Process
attr_reader :entry
attr_reader :num
attr_reader :pid
attr_reader :port
def initialize(entry, num)
def initialize(entry, num, port)
@entry = entry
@num = num
@port = port
end
def run(pipe, basedir, environment)
Dir.chdir(basedir) do
with_environment(environment) do
io = IO.popen(["/Users/david/Code/foreman/bin/runner", "#{entry.command}"], "w+")
@pid = io.pid
trap("SIGTERM") { "got sigterm for %d" % @pid }
output pipe, "started with pid %d" % @pid
Thread.new do
until io.eof?
output pipe, io.gets
end
end
with_environment(environment.merge("PORT" => port.to_s)) do
run_process entry.command
end
end
end
@@ -33,11 +27,24 @@ class Foreman::Process
private
def run_process(command)
io = IO.popen([Foreman.runner, replace_command_env(command)], "w+")
@pid = io.pid
trap("SIGTERM") { "got sigterm for %d" % @pid }
output pipe, "started with pid %d" % @pid
Thread.new do
until io.eof?
output pipe, io.gets
end
end
end
def output(pipe, message)
pipe.puts "%s,%s" % [ name, message ]
end
def replace_command
def replace_command_env(command)
command.gsub(/\$(\w+)/) { |e| ENV[e[1..-1]] }
end
def with_environment(environment)