Class: Cumuli::Spawner::App
- Inherits:
-
Object
- Object
- Cumuli::Spawner::App
- Defined in:
- lib/cumuli/spawner/app.rb
Constant Summary collapse
- SIGNALS =
['TERM', 'INT', 'HUP']
Instance Attribute Summary collapse
-
#app_dir ⇒ Object
Returns the value of attribute app_dir.
-
#env ⇒ Object
Returns the value of attribute env.
-
#log_dir ⇒ Object
Returns the value of attribute log_dir.
Instance Method Summary collapse
- #apps ⇒ Object
- #foreman_process ⇒ Object
-
#initialize(options = {}) ⇒ App
constructor
A new instance of App.
- #listen_for_signals ⇒ Object
- #log_and_wait(app, direction) ⇒ Object
- #logger ⇒ Object
- #pid ⇒ Object
- #process_pids ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #wait_for_apps(direction = 'start') ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ App
Returns a new instance of App.
8 9 10 11 12 |
# File 'lib/cumuli/spawner/app.rb', line 8 def initialize(={}) @env = [:env] @log_dir = [:log_dir] || "#{Dir.pwd}/log" @app_dir = [:app_dir] || Dir.pwd end |
Instance Attribute Details
#app_dir ⇒ Object
Returns the value of attribute app_dir.
6 7 8 |
# File 'lib/cumuli/spawner/app.rb', line 6 def app_dir @app_dir end |
#env ⇒ Object
Returns the value of attribute env.
6 7 8 |
# File 'lib/cumuli/spawner/app.rb', line 6 def env @env end |
#log_dir ⇒ Object
Returns the value of attribute log_dir.
6 7 8 |
# File 'lib/cumuli/spawner/app.rb', line 6 def log_dir @log_dir end |
Instance Method Details
#apps ⇒ Object
41 42 43 |
# File 'lib/cumuli/spawner/app.rb', line 41 def apps @apps ||= ProjectManager::Manager.new(app_dir).projects end |
#foreman_process ⇒ Object
37 38 39 |
# File 'lib/cumuli/spawner/app.rb', line 37 def foreman_process @foreman_process ||= Spawner::ForemanProc.new(env, log_dir) end |
#listen_for_signals ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/cumuli/spawner/app.rb', line 53 def listen_for_signals SIGNALS.each do |signal| trap(signal) do puts "#{self.class}: trapped signal #{signal} in #{Process.pid} ... stopping" stop end end end |
#log_and_wait(app, direction) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/cumuli/spawner/app.rb', line 70 def log_and_wait(app, direction) logger.print "#{direction}: waiting for app named '#{app.name}' at #{app.url}" app.send("wait_for_#{direction}") logger.print "#{direction}: application '#{app.name}' on #{app.url} complete" logger.add_space rescue Exception => e stop raise e end |
#logger ⇒ Object
33 34 35 |
# File 'lib/cumuli/spawner/app.rb', line 33 def logger @logger = StdoutLogger.new end |
#pid ⇒ Object
49 50 51 |
# File 'lib/cumuli/spawner/app.rb', line 49 def pid foreman_process.group_id end |
#process_pids ⇒ Object
45 46 47 |
# File 'lib/cumuli/spawner/app.rb', line 45 def process_pids PS.new.family end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cumuli/spawner/app.rb', line 14 def start return if foreman_process.started? Dir.chdir(app_dir) do listen_for_signals logger.print "Starting ..." foreman_process.start wait_for_apps end end |
#stop ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/cumuli/spawner/app.rb', line 25 def stop if foreman_process.started? foreman_process.stop wait_for_apps('stop') @foreman_process = nil end end |
#wait_for_apps(direction = 'start') ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/cumuli/spawner/app.rb', line 62 def wait_for_apps(direction = 'start') logger.add_space apps.each do |app| log_and_wait(app, direction) end logger.add_space end |