Class: PhusionPassenger::Standalone::AppFinder

Class PhusionPassenger::Standalone::AppFinder |
In: | lib/phusion_passenger/standalone/app_finder.rb
Parent: | Object

Security note: can run arbitrary ruby code by evaluating passenger.conf

Methods

- looks_like_app_directory?
- monitor
- new
- scan

Attributes

[R] | apps |
[RW] | dirs |

Public Class methods
looks_like_app_directory?(dir)

[ show source ]

        # File lib/phusion_passenger/standalone/app_finder.rb, line 33
    33:         def self.looks_like_app_directory?(dir)
    34:                 return File.exist?("#{dir}/config.ru") ||
    35:                         File.exist?("#{dir}/config/environment.rb") ||
    36:                         File.exist?("#{dir}/passenger_wsgi.py")
    37:         end

new(dirs, options = {})

[ show source ]

        # File lib/phusion_passenger/standalone/app_finder.rb, line 39
    39:         def initialize(dirs, options = {})
    40:                 @dirs = dirs
    41:                 @options = options
    42:         end

Public Instance methods
monitor(termination_pipe) {|new_apps| ...}

[ show source ]

         # File lib/phusion_passenger/standalone/app_finder.rb, line 77
     77:         def monitor(termination_pipe)
     78:                 raise "You must call #scan first" if !@apps
     79:
     80:                 watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
     81:                 if wait_on_io(termination_pipe, 3)
     82:                         return
     83:                 end
     84:
     85:                 while true
     86:                         changed = watcher.wait_for_change
     87:                         watcher.close
     88:                         if changed
     89:                                 old_apps = @apps
     90:                                 # The change could be caused by a write to some passenger.conf file.
     91:                                 # Wait for a short period so that the write has a chance to finish.
     92:                                 if wait_on_io(termination_pipe, 0.25)
     93:                                         return
     94:                                 end
     95:
     96:                                 new_apps = scan
     97:                                 watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
     98:                                 if old_apps != new_apps
     99:                                         yield(new_apps)
    100:                                 end
    101:
    102:                                 # Don't process change events again for a short while,
    103:                                 # but do detect changes while waiting.
    104:                                 if wait_on_io(termination_pipe, 3)
    105:                                         return
    106:                                 end
    107:                         else
    108:                                 return
    109:                         end
    110:                 end
    111:         ensure
    112:                 watcher.close if watcher
    113:         end

scan()

[ show source ]

        # File lib/phusion_passenger/standalone/app_finder.rb, line 44
    44:         def scan
    45:                 apps = []
    46:                 watchlist = []
    47:
    48:                 app_root = find_app_root
    49:                 apps << {
    50:                         :server_names => ["_"],
    51:                         :root => app_root
    52:                 }
    53:                 watchlist << app_root
    54:                 watchlist << "#{app_root}/config" if File.exist?("#{app_root}/config")
    55:                 watchlist << "#{app_root}/passenger.conf" if File.exist?("#{app_root}/passenger.conf")
    56:
    57:                 apps.sort! do |a, b|
    58:                         a[:root] <=> b[:root]
    59:                 end
    60:                 apps.map! do |app|
    61:                         config_filename = File.join(app[:root], "passenger.conf")
    62:                         if File.exist?(config_filename)
    63:                                 local_options = load_config_file(:local_config, config_filename)
    64:                                 merged_options = @options.merge(app)
    65:                                 merged_options.merge!(local_options)
    66:                                 merged_options
    67:                         else
    68:                                 @options.merge(app)
    69:                         end
    70:                 end
    71:
    72:                 @apps = apps
    73:                 @watchlist = watchlist
    74:                 return apps
    75:         end