Class PhusionPassenger::Rack::ApplicationSpawner
In: lib/phusion_passenger/rack/application_spawner.rb
Parent: AbstractServer

Spawning of Rack applications.

Methods

Included Modules

Utils DebugLogging

Classes and Modules

Class PhusionPassenger::Rack::ApplicationSpawner::Error

Public Class methods

The following options are accepted:

  • ‘app_root‘

See SpawnManager#spawn_application for information about the options.

[Source]

     # File lib/phusion_passenger/rack/application_spawner.rb, line 95
 95:         def initialize(options)
 96:                 super()
 97:                 @options          = sanitize_spawn_options(options)
 98:                 @app_root         = @options["app_root"]
 99:                 @canonicalized_app_root = canonicalize_path(@app_root)
100:                 self.max_idle_time = DEFAULT_APP_SPAWNER_MAX_IDLE_TIME
101:                 define_message_handler(:spawn_application, :handle_spawn_application)
102:         end

Spawn an instance of the given Rack application. When successful, an AppProcess object will be returned, which represents the spawned application.

Accepts the same options as SpawnManager#spawn_application.

Raises:

  • AppInitError: The Rack application raised an exception or called exit() during startup.
  • SystemCallError, IOError, SocketError: Something went wrong.

[Source]

    # File lib/phusion_passenger/rack/application_spawner.rb, line 59
59:         def self.spawn_application(options = {})
60:                 options = sanitize_spawn_options(options)
61:                 
62:                 a, b = UNIXSocket.pair
63:                 pid = safe_fork(self.class.to_s, true) do
64:                         a.close
65:                         
66:                         file_descriptors_to_leave_open = [0, 1, 2, b.fileno]
67:                         NativeSupport.close_all_file_descriptors(file_descriptors_to_leave_open)
68:                         close_all_io_objects_for_fds(file_descriptors_to_leave_open)
69:                         
70:                         channel = MessageChannel.new(b)
71:                         app = nil
72:                         success = report_app_init_status(channel) do
73:                                 prepare_app_process('config.ru', options)
74:                                 app = load_rack_app
75:                                 after_loading_app_code(options)
76:                         end
77:                         if success
78:                                 start_request_handler(channel, app, false, options)
79:                         end
80:                 end
81:                 b.close
82:                 Process.waitpid(pid) rescue nil
83:                 
84:                 channel = MessageChannel.new(a)
85:                 unmarshal_and_raise_errors(channel, options["print_exceptions"], "rack")
86:                 
87:                 # No exception was raised, so spawning succeeded.
88:                 return AppProcess.read_from_channel(channel)
89:         end

Public Instance methods

Spawns an instance of the Rack application. When successful, an AppProcess object will be returned, which represents the spawned Rack application.

options will be passed to the request handler‘s constructor.

Raises:

[Source]

     # File lib/phusion_passenger/rack/application_spawner.rb, line 112
112:         def spawn_application(options = {})
113:                 connect do |channel|
114:                         channel.write("spawn_application", *options.to_a.flatten)
115:                         return AppProcess.read_from_channel(channel)
116:                 end
117:         rescue SystemCallError, IOError, SocketError => e
118:                 raise Error, "The application spawner server exited unexpectedly: #{e}"
119:         end

Overrided from AbstractServer#start.

May raise these additional exceptions:

[Source]

     # File lib/phusion_passenger/rack/application_spawner.rb, line 127
127:         def start
128:                 super
129:                 begin
130:                         channel = MessageChannel.new(@owner_socket)
131:                         unmarshal_and_raise_errors(channel, @options["print_exceptions"])
132:                 rescue IOError, SystemCallError, SocketError => e
133:                         stop if started?
134:                         raise Error, "The application spawner server exited unexpectedly: #{e}"
135:                 rescue
136:                         stop if started?
137:                         raise
138:                 end
139:         end

[Validate]