Class: Foreman::Engine
- Inherits:
-
Object
- Object
- Foreman::Engine
- Defined in:
- lib/foreman/engine.rb
Constant Summary collapse
- COLORS =
%w( cyan yellow green magenta red blue intense_cyan intense_yellow intense_green intense_magenta intense_red, intense_blue )
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
- #apply_environment! ⇒ Object
-
#initialize(procfile, options = {}) ⇒ Engine
constructor
A new instance of Engine.
- #port_for(process, num, base_port = nil) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(procfile, options = {}) ⇒ Engine
Returns a new instance of Engine.
23 24 25 26 27 28 29 |
# File 'lib/foreman/engine.rb', line 23 def initialize(procfile, ={}) @procfile = Foreman::Procfile.new(procfile) @directory = [:app_root] || File.(File.dirname(procfile)) @options = .dup @environment = read_environment_files([:env]) @output_mutex = Mutex.new end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
15 16 17 |
# File 'lib/foreman/engine.rb', line 15 def directory @directory end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
13 14 15 |
# File 'lib/foreman/engine.rb', line 13 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.
14 15 16 |
# File 'lib/foreman/engine.rb', line 14 def procfile @procfile end |
Instance Method Details
#apply_environment! ⇒ Object
50 51 52 |
# File 'lib/foreman/engine.rb', line 50 def apply_environment! environment.each { |k,v| ENV[k] = v } end |
#port_for(process, num, base_port = nil) ⇒ Object
44 45 46 47 48 |
# File 'lib/foreman/engine.rb', line 44 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 |
#start ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/foreman/engine.rb', line 31 def start proctitle "ruby: foreman master" termtitle "#{File.basename(@directory)} - foreman" trap("TERM") { puts "SIGTERM received"; terminate_gracefully } trap("INT") { puts "SIGINT received"; terminate_gracefully } assign_colors spawn_processes watch_for_output watch_for_termination end |