Class: PhusionPassenger::AppProcess
- Defined in:
- lib/phusion_passenger/app_process.rb
Overview
Contains various information about an application process.
Instance Attribute Summary collapse
-
#app_root ⇒ Object
readonly
The root directory of this application process.
-
#owner_pipe ⇒ Object
readonly
The owner pipe of the application instance (an IO object).
-
#pid ⇒ Object
readonly
This process’s PID.
-
#server_sockets ⇒ Object
readonly
A hash containing all server sockets that this application process listens on.
Class Method Summary collapse
-
.detect_framework_version(app_root) ⇒ Object
-
Returns the Ruby on Rails version that the application requires.
-
-
.read_from_channel(channel) ⇒ Object
Construct an AppProcess by reading information from the given MessageChannel.
Instance Method Summary collapse
-
#close ⇒ Object
Close the connection with the application process.
-
#initialize(app_root, pid, owner_pipe, server_sockets) ⇒ AppProcess
constructor
Creates a new AppProcess instance.
-
#write_to_channel(channel) ⇒ Object
Write this AppProcess’s information over the given MessageChannel.
Constructor Details
#initialize(app_root, pid, owner_pipe, server_sockets) ⇒ AppProcess
Creates a new AppProcess instance. The parameters correspond with the attributes of the same names. No exceptions will be thrown.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/phusion_passenger/app_process.rb', line 137 def initialize(app_root, pid, owner_pipe, server_sockets) @app_root = app_root @pid = pid @owner_pipe = owner_pipe # We copy the values like this so one can directly pass # AbstractRequestHandler#server_sockets as arguments # without having AppProcess store references to the socket # IO objects. @server_sockets = {} server_sockets.each_pair do |name, value| @server_sockets[name] = [value[0], value[1]] end end |
Instance Attribute Details
#app_root ⇒ Object (readonly)
The root directory of this application process.
31 32 33 |
# File 'lib/phusion_passenger/app_process.rb', line 31 def app_root @app_root end |
#owner_pipe ⇒ Object (readonly)
The owner pipe of the application instance (an IO object). Please see RequestHandler for a description of the owner pipe.
53 54 55 |
# File 'lib/phusion_passenger/app_process.rb', line 53 def owner_pipe @owner_pipe end |
#pid ⇒ Object (readonly)
This process’s PID.
34 35 36 |
# File 'lib/phusion_passenger/app_process.rb', line 34 def pid @pid end |
#server_sockets ⇒ Object (readonly)
A hash containing all server sockets that this application process listens on. The hash is in the form of:
{
name1 => [socket_address1, socket_type1],
name2 => [socket_address2, socket_type2],
...
}
name
is a Symbol. socket_addressx
is the address of the socket and socket_type1
is the socket’s type (either ‘unix’ or ‘tcp’). There’s guaranteed to be at least one server socket, namely one with the name :main
.
49 50 51 |
# File 'lib/phusion_passenger/app_process.rb', line 49 def server_sockets @server_sockets 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.
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 92 93 94 95 |
# File 'lib/phusion_passenger/app_process.rb', line 59 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 |
.read_from_channel(channel) ⇒ Object
Construct an AppProcess by reading information from the given MessageChannel. The other side of the channel must be writing AppProcess information using AppProcess#write_to_channel.
Might raise SystemCallError, IOError or SocketError.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/phusion_passenger/app_process.rb', line 102 def self.read_from_channel(channel) app_root, pid, n_server_sockets = channel.read if app_root.nil? raise IOError, "Connection closed" end server_sockets = {} n_server_sockets.to_i.times do = channel.read if .nil? raise IOError, "Connection closed" end name = .shift server_sockets[name.to_sym] = end owner_pipe = channel.recv_io return new(app_root, pid.to_i, owner_pipe, server_sockets) end |
Instance Method Details
#close ⇒ Object
Close the connection with the application process. If there are no other processes that have connections to this application process, then it will shutdown as soon as possible.
See also AbstractRequestHandler#owner_pipe.
157 158 159 |
# File 'lib/phusion_passenger/app_process.rb', line 157 def close @owner_pipe.close rescue nil end |
#write_to_channel(channel) ⇒ Object
Write this AppProcess’s information over the given MessageChannel. The other side must read the information using AppProces.read_from_channel.
Might raise SystemCallError, IOError or SocketError.
127 128 129 130 131 132 133 |
# File 'lib/phusion_passenger/app_process.rb', line 127 def write_to_channel(channel) channel.write(@app_root, @pid, @server_sockets.size) @server_sockets.each_pair do |name, value| channel.write(name.to_s, *value) end channel.send_io(@owner_pipe) end |