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

Class for spawning Rack applications.

### Methods

spawn_application spawn_application

### Included Modules

Utils

### Public Class methods

spawn_application(*args)

[Source]

        # File lib/phusion_passenger/rack/application_spawner.rb, line 39
    39:         def self.spawn_application(*args)
    40:                 @@instance ||= ApplicationSpawner.new
    41:                 @@instance.spawn_application(*args)
    42:         end

### Public Instance methods

spawn_application(app_root, options = {})

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

Accepts the same options as Railz::ApplicationSpawner#initialize.

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 54
    54:         def spawn_application(app_root, options = {})
    55:                 options = sanitize_spawn_options(options)
    56:
    57:                 a, b = UNIXSocket.pair
    58:                 pid = safe_fork(self.class.to_s, true) do
    59:                         a.close
    60:
    61:                         file_descriptors_to_leave_open = [0, 1, 2, b.fileno]
    62:                         NativeSupport.close_all_file_descriptors(file_descriptors_to_leave_open)
    63:                         close_all_io_objects_for_fds(file_descriptors_to_leave_open)
    64:
    65:                         run(MessageChannel.new(b), app_root, options)
    66:                 end
    67:                 b.close
    68:                 Process.waitpid(pid) rescue nil
    69:
    70:                 channel = MessageChannel.new(a)
    71:                 unmarshal_and_raise_errors(channel, !!options["print_exceptions"], "rack")
    72:
    73:                 # No exception was raised, so spawning succeeded.
    74:                 pid, socket_name, socket_type = channel.read
    75:                 if pid.nil?
    76:                         raise IOError, "Connection closed"
    77:                 end
    78:                 owner_pipe = channel.recv_io
    79:                 return Application.new(@app_root, pid, socket_name,
    80:                         socket_type, owner_pipe)
    81:         end

[Validate]