Class: Foreman::Engine
- Inherits:
-
Object
- Object
- Foreman::Engine
- Extended by:
- Term::ANSIColor
- Defined in:
- lib/foreman/engine.rb
Constant Summary collapse
- COLORS =
[ cyan, yellow, green, magenta, red ]
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#procfile ⇒ Object
readonly
Returns the value of attribute procfile.
Instance Method Summary collapse
- #execute(name, options = {}) ⇒ Object
-
#initialize(procfile) ⇒ Engine
constructor
A new instance of Engine.
- #port_for(process, num, base_port = nil) ⇒ Object
- #processes ⇒ Object
- #start(options = {}) ⇒ Object
Constructor Details
#initialize(procfile) ⇒ Engine
Returns a new instance of Engine.
18 19 20 21 |
# File 'lib/foreman/engine.rb', line 18 def initialize(procfile) @procfile = read_procfile(procfile) @directory = File.(File.dirname(procfile)) end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
12 13 14 |
# File 'lib/foreman/engine.rb', line 12 def directory @directory end |
#procfile ⇒ Object (readonly)
Returns the value of attribute procfile.
11 12 13 |
# File 'lib/foreman/engine.rb', line 11 def procfile @procfile end |
Instance Method Details
#execute(name, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/foreman/engine.rb', line 48 def execute(name, ={}) fork processes[name], trap("TERM") { kill_and_exit("TERM") } trap("INT") { kill_and_exit("INT") } watch_for_termination end |
#port_for(process, num, base_port = nil) ⇒ Object
57 58 59 60 61 |
# File 'lib/foreman/engine.rb', line 57 def port_for(process, num, base_port=nil) base_port ||= 5000 offset = processes.keys.sort.index(process.name) * 100 base_port.to_i + offset + num - 1 end |
#processes ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/foreman/engine.rb', line 23 def processes @processes ||= begin 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 hash.update(process.name => process) end end end |
#start(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/foreman/engine.rb', line 35 def start(={}) proctitle "ruby: foreman master" processes.each do |name, process| fork process, end trap("TERM") { kill_and_exit("TERM") } trap("INT") { kill_and_exit("INT") } watch_for_termination end |