wip
This commit is contained in:
+19
-12
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user