lib/foreman/engine.rb in foreman-0.9.0.beta.1 vs lib/foreman/engine.rb in foreman-0.9.0

- old
+ new

@@ -6,38 +6,51 @@ require "term/ansicolor" require "fileutils" class Foreman::Engine - attr_reader :pstypes + attr_reader :procfile attr_reader :directory extend Term::ANSIColor COLORS = [ cyan, yellow, green, magenta, red ] - def initialize(pstypes) - @pstypes = read_pstypes(pstypes) - @directory = File.expand_path(File.dirname(pstypes)) + def initialize(procfile) + @procfile = read_procfile(procfile) + @directory = File.expand_path(File.dirname(procfile)) end def processes @processes ||= begin - pstypes.split("\n").inject({}) do |hash, line| + @order = [] + procfile.split("\n").inject({}) do |hash, line| next if line.strip == "" name, command = line.split(" ", 2) process = Foreman::Process.new(name, command) process.color = next_color + @order << process.name hash.update(process.name => process) end end end + def process_order + processes + @order + end + + def processes_in_order + process_order.map do |name| + [name, processes[name]] + end + end + def start(options={}) proctitle "ruby: foreman master" - processes.each do |name, process| + processes_in_order.each do |name, process| fork process, options end trap("TERM") { puts "SIGTERM received"; kill_all("TERM") } trap("INT") { puts "SIGINT received"; kill_all("INT") } @@ -76,11 +89,11 @@ pid = Process.fork do run(process) end - info "started with pid #{pid}, PORT=#{port}", process + info "started with pid #{pid}", process running_processes[pid] = process end def run(process, log_to_file=true) proctitle "ruby: foreman #{process.name}" @@ -142,11 +155,11 @@ def proctitle(title) $0 = title end - def read_pstypes(pstypes) - File.read(pstypes) + def read_procfile(procfile) + File.read(procfile) end def watch_for_termination pid, status = Process.wait2 process = running_processes.delete(pid)