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.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#procfile ⇒ Object
readonly
Returns the value of attribute procfile.
Instance Method Summary collapse
- #execute(name) ⇒ Object
-
#initialize(procfile, options = {}) ⇒ Engine
constructor
A new instance of Engine.
- #port_for(process, num, base_port = nil) ⇒ Object
- #processes ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(procfile, options = {}) ⇒ Engine
Returns a new instance of Engine.
22 23 24 25 26 27 |
# File 'lib/foreman/engine.rb', line 22 def initialize(procfile, ={}) @procfile = Foreman::Procfile.new(procfile) @directory = File.(File.dirname(procfile)) @options = @environment = read_environment_files([:env]) end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
14 15 16 |
# File 'lib/foreman/engine.rb', line 14 def directory @directory end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
15 16 17 |
# File 'lib/foreman/engine.rb', line 15 def environment @environment end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/foreman/engine.rb', line 16 def @options end |
#procfile ⇒ Object (readonly)
Returns the value of attribute procfile.
13 14 15 |
# File 'lib/foreman/engine.rb', line 13 def procfile @procfile end |
Instance Method Details
#execute(name) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/foreman/engine.rb', line 43 def execute(name) fork procfile[name] trap("TERM") { puts "SIGTERM received"; terminate_gracefully } trap("INT") { puts "SIGINT received"; terminate_gracefully } watch_for_termination end |
#port_for(process, num, base_port = nil) ⇒ Object
56 57 58 59 60 |
# File 'lib/foreman/engine.rb', line 56 def port_for(process, num, base_port=nil) base_port ||= 5000 offset = procfile.process_names.index(process.name) * 100 base_port.to_i + offset + num - 1 end |
#processes ⇒ Object
52 53 54 |
# File 'lib/foreman/engine.rb', line 52 def processes procfile.processes end |
#start ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/foreman/engine.rb', line 29 def start proctitle "ruby: foreman master" processes.each do |process| process.color = next_color fork process end trap("TERM") { puts "SIGTERM received"; terminate_gracefully } trap("INT") { puts "SIGINT received"; terminate_gracefully } watch_for_termination end |