Represents a single application instance.

Methods
Attributes
[R] app_root The root directory of this application, i.e. the directory that contains ‘app/’, ‘public/’, etc.
[R] listen_socket_name The name of the Unix socket on which the application instance will accept new connections.
[R] owner_pipe The owner pipe of the application instance (an IO object). Please see RequestHandler for a description of the owner pipe.
[R] pid The process ID of this application instance.
Public Class methods
detect_framework_version(app_root)
  • 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/passenger/application.rb, line 44
44:         def self.detect_framework_version(app_root)
45:                 if File.directory?("#{app_root}/vendor/rails/railties")
46:                         # NOTE: We must check for 'rails/railties' and not just 'rails'.
47:                         # Typo's vendor directory contains an empty 'rails' directory.
48:                         return :vendor
49:                 end
50:                 
51:                 environment_rb = File.read("#{app_root}/config/environment.rb")
52:                 environment_rb =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
53:                 gem_version_spec = $1
54:                 if gem_version_spec.nil?
55:                         return nil
56:                 end
57:                 
58:                 search_results = Gem.cache.search(Gem::Dependency.new('rails', gem_version_spec), true)
59:                 found_version = search_results.map do |x|
60:                         x.version.version
61:                 end.sort.last
62:                 if found_version.nil?
63:                         # If this error was reported before, then the cache might be out of
64:                         # date because the Rails version may have been installed now.
65:                         # So we reload the RubyGems cache and try again.
66:                         Gem.clear_paths
67:                         search_results = Gem.cache.search(Gem::Dependency.new('rails', gem_version_spec), true)
68:                         found_version = search_results.map do |x|
69:                                 x.version.version
70:                         end.sort.last
71:                 end
72:                 
73:                 if found_version.nil?
74:                         raise VersionNotFound.new("There is no Ruby on Rails version " <<
75:                                 "installed that matches version \"#{gem_version_spec}\"",
76:                                 gem_version_spec)
77:                 else
78:                         return found_version
79:                 end
80:         end
new(app_root, pid, listen_socket_name, using_abstract_namespace, owner_pipe)

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

    # File lib/passenger/application.rb, line 84
84:         def initialize(app_root, pid, listen_socket_name, using_abstract_namespace, owner_pipe)
85:                 @app_root = app_root
86:                 @pid = pid
87:                 @listen_socket_name = listen_socket_name
88:                 @using_abstract_namespace = using_abstract_namespace
89:                 @owner_pipe = owner_pipe
90:         end
Public Instance methods
close()

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.

     # File lib/passenger/application.rb, line 106
106:         def close
107:                 @owner_pipe.close rescue nil
108:         end
using_abstract_namespace?()

Whether listen_socket_name refers to a Unix socket in the abstract namespace. In any case, listen_socket_name does not contain the leading null byte.

Note that at the moment, only Linux seems to support abstract namespace Unix sockets.

    # File lib/passenger/application.rb, line 97
97:         def using_abstract_namespace?
98:                 return @using_abstract_namespace
99:         end