Class: PhusionPassenger::Application

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

Overview

Represents a single application instance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_root, pid, listen_socket_name, listen_socket_type, owner_pipe) ⇒ Application

Creates a new instance of Application. The parameters correspond with the attributes of the same names. No exceptions will be thrown.



95
96
97
98
99
100
101
# File 'lib/phusion_passenger/application.rb', line 95

def initialize(app_root, pid, listen_socket_name, listen_socket_type, owner_pipe)
	@app_root = app_root
	@pid = pid
	@listen_socket_name = listen_socket_name
	@listen_socket_type = listen_socket_type
	@owner_pipe = owner_pipe
end

Instance Attribute Details

#app_rootObject (readonly)

The root directory of this application, i.e. the directory that contains ‘app/’, ‘public/’, etc.



32
33
34
# File 'lib/phusion_passenger/application.rb', line 32

def app_root
  @app_root
end

#listen_socket_nameObject (readonly)

The name of the socket on which the application instance will accept new connections. See #listen_socket_type on how one should interpret this value.



40
41
42
# File 'lib/phusion_passenger/application.rb', line 40

def listen_socket_name
  @listen_socket_name
end

#listen_socket_typeObject (readonly)

The type of socket that #listen_socket_name refers to. Currently this is always ‘unix’, which means that #listen_socket_name refers to the filename of a Unix domain socket.



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

def listen_socket_type
  @listen_socket_type
end

#owner_pipeObject (readonly)

The owner pipe of the application instance (an IO object). Please see RequestHandler for a description of the owner pipe.



49
50
51
# File 'lib/phusion_passenger/application.rb', line 49

def owner_pipe
  @owner_pipe
end

#pidObject (readonly)

The process ID of this application instance.



35
36
37
# File 'lib/phusion_passenger/application.rb', line 35

def pid
  @pid
end

Class Method Details

.detect_framework_version(app_root) ⇒ Object

  • Returns the Ruby on Rails version that the application requires.

  • Returns :vendor if the application has a vendored Rails.

  • Returns nil if the application doesn’t specify a particular version.

Raises VersionNotFound if the required Rails version is not installed.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/phusion_passenger/application.rb', line 55

def self.detect_framework_version(app_root)
	if File.directory?("#{app_root}/vendor/rails/railties")
		# NOTE: We must check for 'rails/railties' and not just 'rails'.
		# Typo's vendor directory contains an empty 'rails' directory.
		return :vendor
	end
	
	environment_rb = File.read("#{app_root}/config/environment.rb")
	environment_rb =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
	gem_version_spec = $1
	if gem_version_spec.nil?
		return nil
	end
	
	search_results = Gem.cache.search(Gem::Dependency.new('rails', gem_version_spec), true)
	found_version = search_results.map do |x|
		x.version.version
	end.sort.last
	if found_version.nil?
		# If this error was reported before, then the cache might be out of
		# date because the Rails version may have been installed now.
		# So we reload the RubyGems cache and try again.
		Gem.clear_paths
		search_results = Gem.cache.search(Gem::Dependency.new('rails', gem_version_spec), true)
		found_version = search_results.map do |x|
			x.version.version
		end.sort.last
	end
	
	if found_version.nil?
		raise VersionNotFound.new("There is no Ruby on Rails version " <<
			"installed that matches version \"#{gem_version_spec}\"",
			gem_version_spec)
	else
		return found_version
	end
end

Instance Method Details

#closeObject

Close the connection with the application instance. If there are no other processes that have connections to this application instance, then it will shutdown as soon as possible.

See also AbstractRequestHandler#owner_pipe.



108
109
110
# File 'lib/phusion_passenger/application.rb', line 108

def close
	@owner_pipe.close rescue nil
end