Class: Foreman::Engine

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

Constant Summary collapse

COLORS =
[ cyan, yellow, green, magenta, red ]

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#environmentObject (readonly)

Returns the value of attribute environment.



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

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.



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

#processesObject



52
53
54
# File 'lib/foreman/engine.rb', line 52

def processes
  procfile.processes
end

#startObject



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