Class: Foreman::Engine
- Inherits:
-
Object
- Object
- Foreman::Engine
- Defined in:
- lib/foreman/engine.rb
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
-
#initialize(procfile) ⇒ Engine
constructor
A new instance of Engine.
- #processes ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(procfile) ⇒ Engine
Returns a new instance of Engine.
9 10 11 12 |
# File 'lib/foreman/engine.rb', line 9 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.
7 8 9 |
# File 'lib/foreman/engine.rb', line 7 def directory @directory end |
#procfile ⇒ Object (readonly)
Returns the value of attribute procfile.
6 7 8 |
# File 'lib/foreman/engine.rb', line 6 def procfile @procfile end |
Instance Method Details
#processes ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/foreman/engine.rb', line 14 def processes @processes ||= begin procfile.split("\n").inject({}) do |hash, line| next if line.strip == "" process = Foreman::Process.new(*line.split(" ", 2)) hash.update(process.name => process) end end end |
#start ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/foreman/engine.rb', line 24 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") } while true pid, status = Process.wait2 process = running_processes.delete(pid) info "exited with code #{status}", process fork process end end |