lib/foreman/engine.rb in foreman-0.20.0 vs lib/foreman/engine.rb in foreman-0.21.0

- old
+ new

@@ -9,18 +9,22 @@ class Foreman::Engine attr_reader :procfile attr_reader :directory + attr_reader :environment + attr_reader :options extend Term::ANSIColor COLORS = [ cyan, yellow, green, magenta, red ] - def initialize(procfile) + def initialize(procfile, options={}) @procfile = read_procfile(procfile) @directory = File.expand_path(File.dirname(procfile)) + @options = options + @environment = read_environment(options[:env]) end def processes @processes ||= begin @order = [] @@ -48,29 +52,26 @@ process_order.map do |name| [name, processes[name]] end end - def start(options={}) - environment = read_environment(options[:env]) - + def start proctitle "ruby: foreman master" processes_in_order.each do |name, process| - fork process, options, environment + fork process end trap("TERM") { puts "SIGTERM received"; terminate_gracefully } trap("INT") { puts "SIGINT received"; terminate_gracefully } watch_for_termination end - def execute(name, options={}) - environment = read_environment(options[:env]) + def execute(name) - fork processes[name], options, environment + fork processes[name] trap("TERM") { puts "SIGTERM received"; terminate_gracefully } trap("INT") { puts "SIGINT received"; terminate_gracefully } watch_for_termination @@ -82,19 +83,19 @@ base_port.to_i + offset + num - 1 end private ###################################################################### - def fork(process, options={}, environment={}) - concurrency = Foreman::Utils.parse_concurrency(options[:concurrency]) + def fork(process) + concurrency = Foreman::Utils.parse_concurrency(@options[:concurrency]) 1.upto(concurrency[process.name]) do |num| - fork_individual(process, num, port_for(process, num, options[:port]), environment) + fork_individual(process, num, port_for(process, num, @options[:port])) end end - def fork_individual(process, num, port, environment) - environment.each { |k,v| ENV[k] = v } + def fork_individual(process, num, port) + @environment.each { |k,v| ENV[k] = v } ENV["PORT"] = port.to_s ENV["PS"] = "#{process.name}.#{num}" pid = Process.fork do