Class
PhusionPassenger::WSGI::ApplicationSpawner

In: | lib/phusion_passenger/wsgi/application_spawner.rb
Parent: | Object

Class for spawning WSGI applications.

Methods

- spawn_application
- spawn_application

Included Modules

- Utils

Constants

REQUEST_HANDLER | = | File.expand_path(File.dirname(__FILE__) + "/request_handler.py")

Public Class methods
spawn_application(*args)

[ show source ]

        # File lib/phusion_passenger/wsgi/application_spawner.rb, line 36
    36:         def self.spawn_application(*args)
    37:                 @@instance ||= ApplicationSpawner.new
    38:                 @@instance.spawn_application(*args)
    39:         end

Public Instance methods
spawn_application(app_root, lower_privilege = true, lowest_user = "nobody", environment = "production")

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

Raises:

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

[ show source ]

        # File lib/phusion_passenger/wsgi/application_spawner.rb, line 49
    49:         def spawn_application(app_root, lower_privilege = true, lowest_user = "nobody", environment = "production")
    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, lower_privilege, lowest_user, environment)
    59:                 end
    60:                 b.close
    61:                 Process.waitpid(pid) rescue nil
    62:
    63:                 channel = MessageChannel.new(a)
    64:                 pid, socket_name, socket_type = channel.read
    65:                 if pid.nil?
    66:                         raise IOError, "Connection closed"
    67:                 end
    68:                 owner_pipe = channel.recv_io
    69:                 return Application.new(@app_root, pid, socket_name,
    70:                         socket_type, owner_pipe)
    71:         end