Class: PhusionPassenger::Standalone::AppFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/phusion_passenger/standalone/app_finder.rb

Defined Under Namespace

Classes: ConfigLoadError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dirs, options = {}) ⇒ AppFinder

Returns a new instance of AppFinder.



40
41
42
43
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 40

def initialize(dirs, options = {})
	@dirs = dirs
	@options = options.dup
end

Instance Attribute Details

#appsObject (readonly)

Returns the value of attribute apps.



30
31
32
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 30

def apps
  @apps
end

#dirsObject

Returns the value of attribute dirs.



29
30
31
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 29

def dirs
  @dirs
end

Class Method Details

.looks_like_app_directory?(dir) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 32

def self.looks_like_app_directory?(dir)
	return File.exist?("#{dir}/config.ru") ||
		File.exist?("#{dir}/config/environment.rb") ||
		File.exist?("#{dir}/passenger_wsgi.py") ||
		File.exist?("#{dir}/app.js") ||
		File.exist?("#{dir}/.meteor")
end

Instance Method Details

#global_optionsObject



45
46
47
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 45

def global_options
	return @options
end

#monitor(termination_pipe) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 79

def monitor(termination_pipe)
	raise "You must call #scan first" if !@apps
	
	watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
	if wait_on_io(termination_pipe, 3)
		return
	end
	
	while true
		changed = watcher.wait_for_change
		watcher.close
		if changed
			old_apps = @apps
			# The change could be caused by a write to some passenger.conf file.
			# Wait for a short period so that the write has a chance to finish.
			if wait_on_io(termination_pipe, 0.25)
				return
			end
			
			new_apps = scan
			watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
			if old_apps != new_apps
				yield(new_apps)
			end
			
			# Don't process change events again for a short while,
			# but do detect changes while waiting.
			if wait_on_io(termination_pipe, 3)
				return
			end
		else
			return
		end
	end
ensure
	watcher.close if watcher
end

#multi_mode?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 121

def multi_mode?
	return !single_mode?
end

#scanObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 49

def scan
	apps = []
	watchlist = []
	
	if single_mode?
		app_root = find_app_root
		apps << {
			:server_names => ["_"],
			:root => app_root
		}
		watchlist << app_root
		watchlist << "#{app_root}/config" if File.exist?("#{app_root}/config")
		watchlist << "#{app_root}/passenger-standalone.json" if File.exist?("#{app_root}/passenger-standalone.json")
		
		config_filename = File.join(app_root, "passenger-standalone.json")
		if File.exist?(config_filename)
			global_options = load_config_file!(:global_config, config_filename)
			@options.merge!(global_options)
		end

		apps.map! do |app|
			@options.merge(app)
		end
	end

	@apps = apps
	@watchlist = watchlist
	return apps
end

#single_mode?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 117

def single_mode?
	return true
end