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.
-
#procfile ⇒ Object
readonly
Returns the value of attribute procfile.
Instance Method Summary collapse
- #execute(name, options = {}) ⇒ Object
-
#initialize(procfile, options = {}) ⇒ Engine
constructor
A new instance of Engine.
- #port_for(process, num, base_port = nil) ⇒ Object
- #process_order ⇒ Object
- #processes ⇒ Object
- #processes_in_order ⇒ Object
- #start(options = {}) ⇒ Object
Constructor Details
#initialize(procfile, options = {}) ⇒ Engine
Returns a new instance of Engine.
19 20 21 22 23 24 25 26 27 |
# File 'lib/foreman/engine.rb', line 19 def initialize(procfile, ={}) @procfile = if procfile.end_with? ".rb" eval_procfile(procfile, ) else read_procfile(procfile) end @directory = File.(File.dirname(procfile)) end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
13 14 15 |
# File 'lib/foreman/engine.rb', line 13 def directory @directory end |
#procfile ⇒ Object (readonly)
Returns the value of attribute procfile.
12 13 14 |
# File 'lib/foreman/engine.rb', line 12 def procfile @procfile end |
Instance Method Details
#execute(name, options = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/foreman/engine.rb', line 73 def execute(name, ={}) environment = read_environment([:env]) fork processes[name], , environment 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
84 85 86 87 88 |
# File 'lib/foreman/engine.rb', line 84 def port_for(process, num, base_port=nil) base_port ||= 5000 offset = processes_in_order.map { |p| p.first }.index(process.name) * 100 base_port.to_i + offset + num - 1 end |
#process_order ⇒ Object
47 48 49 50 |
# File 'lib/foreman/engine.rb', line 47 def process_order processes @order.uniq end |
#processes ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/foreman/engine.rb', line 29 def processes @processes ||= begin @order = [] procfile.split("\n").inject({}) do |hash, line| next hash if line.strip == "" name, command = line.split(/ *: +/, 2) unless command warn_deprecated_procfile! name, command = line.split(/ +/, 2) end process = Foreman::Process.new(name, command) process.color = next_color @order << process.name hash.update(process.name => process) end end end |
#processes_in_order ⇒ Object
52 53 54 55 56 |
# File 'lib/foreman/engine.rb', line 52 def processes_in_order process_order.map do |name| [name, processes[name]] end end |
#start(options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/foreman/engine.rb', line 58 def start(={}) environment = read_environment([:env]) proctitle "ruby: foreman master" processes_in_order.each do |name, process| fork process, , environment end trap("TERM") { puts "SIGTERM received"; terminate_gracefully } trap("INT") { puts "SIGINT received"; terminate_gracefully } watch_for_termination end |