Parent

Class/Module Index [+]

Quicksearch

PhusionPassenger::AppProcess

Contains various information about an application process.

Attributes

app_root[R]

The root directory of this application process.

owner_pipe[R]

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

pid[R]

This process's PID.

server_sockets[R]

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.

Public Class Methods

detect_framework_version(app_root) click to toggle source
  • 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.

# 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 = search_gem('rails', gem_version_spec)
        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 = search_gem('rails', gem_version_spec)
                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
new(app_root, pid, owner_pipe, server_sockets) click to toggle source

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

# File lib/phusion_passenger/app_process.rb, line 149
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
read_from_channel(channel) click to toggle source

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.

# File lib/phusion_passenger/app_process.rb, line 114
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
                message = channel.read
                if message.nil?
                        raise IOError, "Connection closed"
                end
                name = message.shift
                server_sockets[name.to_sym] = message
        end
        
        owner_pipe = channel.recv_io
        
        return new(app_root, pid.to_i, owner_pipe, server_sockets)
end
search_gem(gem_name, gem_version_spec) click to toggle source
# File lib/phusion_passenger/app_process.rb, line 97
def self.search_gem(gem_name, gem_version_spec)
        if defined?(Gem::Specification) && Gem::Specification.respond_to?(:find_all_by_name)
                return Gem::Specification.find_all_by_name(gem_name, gem_version_spec)
        elsif Gem.respond_to?(:source_index)
                dep = Gem::Dependency.new(gem_name, gem_version_spec)
                return Gem.source_index.search(dep, true)
        else
                dep = Gem::Dependency.new(gem_name, gem_version_spec)
                return Gem.cache.search(dep, true)
        end
end

Public Instance Methods

close() click to toggle source

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.

# File lib/phusion_passenger/app_process.rb, line 169
def close
        @owner_pipe.close rescue nil
end
write_to_channel(channel) click to toggle source

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.

# File lib/phusion_passenger/app_process.rb, line 139
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.