Class for spawning Rack applications.
Methods
Included Modules
Public Class methods
[ show source ]
# File lib/phusion_passenger/rack/application_spawner.rb, line 42 42: def self.spawn_application(*args) 43: @@instance ||= ApplicationSpawner.new 44: @@instance.spawn_application(*args) 45: end
Public Instance methods
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.
[ show source ]
# File lib/phusion_passenger/rack/application_spawner.rb, line 55 55: def spawn_application(app_root, options = {}) 56: options = sanitize_spawn_options(options) 57: 58: a, b = UNIXSocket.pair 59: pid = safe_fork(self.class.to_s, true) do 60: a.close 61: 62: file_descriptors_to_leave_open = [0, 1, 2, b.fileno] 63: NativeSupport.close_all_file_descriptors(file_descriptors_to_leave_open) 64: close_all_io_objects_for_fds(file_descriptors_to_leave_open) 65: 66: run(MessageChannel.new(b), app_root, options) 67: end 68: b.close 69: Process.waitpid(pid) rescue nil 70: 71: channel = MessageChannel.new(a) 72: unmarshal_and_raise_errors(channel, "rack") 73: 74: # No exception was raised, so spawning succeeded. 75: pid, socket_name, socket_type = channel.read 76: if pid.nil? 77: raise IOError, "Connection closed" 78: end 79: owner_pipe = channel.recv_io 80: return Application.new(@app_root, pid, socket_name, 81: socket_type, owner_pipe) 82: end