Class: Foreman::Engine

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options={})
  @procfile  = Foreman::Procfile.new(procfile)
  @directory = options[:app_root] || File.expand_path(File.dirname(procfile))
  @options = options.dup
  @environment = read_environment_files(options[:env])
  @output_mutex = Mutex.new
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



15
16
17
# File 'lib/foreman/engine.rb', line 15

def directory
  @directory
end

#environmentObject (readonly)

Returns the value of attribute environment.



13
14
15
# File 'lib/foreman/engine.rb', line 13

def environment
  @environment
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/foreman/engine.rb', line 16

def options
  @options
end

#procfileObject (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

#startObject



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