Class for spawning WSGI applications.
Methods
Included Modules
Constants
REQUEST_HANDLER | = | File.expand_path(File.dirname(__FILE__) + "/request_handler.py") |
Public Class methods
[ show source ]
# File lib/passenger/wsgi/application_spawner.rb, line 29 29: def self.spawn_application(*args) 30: @@instance ||= ApplicationSpawner.new 31: @@instance.spawn_application(*args) 32: 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/passenger/wsgi/application_spawner.rb, line 42 42: def spawn_application(app_root, lower_privilege = true, lowest_user = "nobody", environment = "production") 43: a, b = UNIXSocket.pair 44: # Double fork in order to prevent zombie processes. 45: pid = safe_fork(self.class.to_s) do 46: safe_fork(self.class.to_s) do 47: a.close 48: run(MessageChannel.new(b), app_root, lower_privilege, lowest_user, environment) 49: end 50: end 51: b.close 52: Process.waitpid(pid) rescue nil 53: 54: channel = MessageChannel.new(a) 55: pid, socket_name, using_abstract_namespace = channel.read 56: if pid.nil? 57: raise IOError, "Connection closed" 58: end 59: owner_pipe = channel.recv_io 60: return Application.new(@app_root, pid, socket_name, 61: using_abstract_namespace == "true", owner_pipe) 62: end