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 34
    34:         def self.spawn_application(*args)
    35:                 @@instance ||= ApplicationSpawner.new
    36:                 @@instance.spawn_application(*args)
    37:         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.

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

[Validate]