Skip to content

Commit

Permalink
ddollarGH-268 Extended environment for running processes with all def…
Browse files Browse the repository at this point in the history
…ined ports
  • Loading branch information
padcom committed Sep 26, 2012
1 parent 46deac7 commit 9bb03f9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/foreman/engine.rb
Expand Up @@ -171,9 +171,11 @@ def port_for(process, instance, index, base=nil)
base = base_port
process_index = @processes.index(process)
end

for i in 0..process_index - 1
index += process.ports.length
index += @processes[i].ports.length
end

base + (index * 100) + (instance - 1)
end

Expand Down Expand Up @@ -261,9 +263,11 @@ def spawn_processes
1.upto(formation[@names[process]]) do |n|
reader, writer = create_pipe
begin
pid = process.run(:output => writer, :env => {
"PORT" => port_for(process, n, 0).to_s
})
env = {}
process.ports.each_with_index { |port, index|
env[port] = port_for(process, n, index).to_s
}
pid = process.run(:output => writer, :env => env)
writer.puts "started with pid #{pid}"
rescue Errno::ENOENT
writer.puts "unknown command: #{process.command}"
Expand Down

0 comments on commit 9bb03f9

Please sign in to comment.