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