Class: Foreman::Engine

Inherits:
Object
  • Object
show all
Extended by:
Env, Term::ANSIColor
Includes:
Env
Defined in:
lib/foreman/engine.rb

Defined Under Namespace

Modules: Env

Constant Summary collapse

COLORS =
[ cyan, yellow, green, magenta, red, blue,
intense_cyan, intense_yellow, intense_green, intense_magenta,
intense_red, intense_blue ]

Instance Attribute Summary collapse

Attributes included from Env

#environment

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Env

apply_environment!, error, read_environment, read_environment_files

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
  @environment = read_environment_files(options[:env])
  @output_mutex = Mutex.new
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



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

def directory
  @directory
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#procfileObject (readonly)

Returns the value of attribute procfile.



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

def procfile
  @procfile
end

Class Method Details

.load_env!(env_file) ⇒ Object



31
32
33
34
# File 'lib/foreman/engine.rb', line 31

def self.load_env!(env_file)
  @environment = read_environment_files(env_file)
  apply_environment!
end

Instance Method Details

#port_for(process, num, base_port = nil) ⇒ Object



49
50
51
52
53
# File 'lib/foreman/engine.rb', line 49

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



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/foreman/engine.rb', line 36

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