0
@@ -145,8 +145,9 @@ class ApplicationSpawner < AbstractServer
0
- # - SystemCallError: Something went wrong.
0
- # - IOError: Something went wrong.
0
+ # - AppInitError: The Ruby on Rails application raised an exception
0
+ # or called exit() during startup.
0
+ # - SystemCallError, IOError, SocketError: Something went wrong.
0
# Double fork to prevent zombie processes.
0
@@ -155,14 +156,14 @@ class ApplicationSpawner < AbstractServer
0
channel = MessageChannel.new(b)
0
-
ok = report_app_init_errors(channel) do
0
+
success = report_app_init_status(channel) do
0
lower_privilege! if @lower_privilege
0
- require 'config/enviroment'
0
+ require 'config/environment'
0
+ start_request_handler(channel)
0
- start_request_handler(channel)
0
rescue SignalException => signal
0
if e.message != RequestHandler::HARD_TERMINATION_SIGNAL &&
0
e.message != RequestHandler::SOFT_TERMINATION_SIGNAL
0
@@ -175,20 +176,16 @@ class ApplicationSpawner < AbstractServer
0
channel = MessageChannel.new(a)
0
+ unmarshal_and_raise_errors(channel)
0
+ # No exception was raised, so spawning succeeded.
0
+ pid, socket_name, using_abstract_namespace = channel.read
0
raise IOError, "Connection closed"
0
- pid, socket_name, using_abstract_namespace = channel.read
0
- raise IOError, "Connection closed"
0
- owner_pipe = server.recv_io
0
- return Application.new(@app_root, pid, socket_name,
0
- using_abstract_namespace == "true", owner_pipe)
0
+ owner_pipe = channel.recv_io
0
+ return Application.new(@app_root, pid, socket_name,
0
+ using_abstract_namespace == "true", owner_pipe)
0
# Overrided from AbstractServer#start.
0
@@ -200,21 +197,13 @@ class ApplicationSpawner < AbstractServer
0
- status = server.read[0]
0
- if status == 'exception'
0
- child_exception = unmarshal_exception(server.read_scalar)
0
- raise AppInitError.new(
0
- "Application '#{@app_root}' raised an exception: " <<
0
- "#{child_exception.class} (#{child_exception.message})",
0
- elsif status == 'exit'
0
- raise AppInitError.new("Application '#{@app_root}' exited during startup")
0
+ unmarshal_and_raise_errors(server)
0
rescue IOError, SystemCallError, SocketError
0
raise Error, "The application spawner server exited unexpectedly"
0
@@ -230,26 +219,65 @@ protected
0
def initialize_server # :nodoc:
0
+
report_app_init_status(client) do0
$0 = "Passenger ApplicationSpawner: #{@app_root}"
0
lower_privilege! if @lower_privilege
0
+ # Run the given block. A message will be sent through _channel_, telling
0
+ # the remote side whether the block raised an exception, called exit(),
0
+ # Returns whether the block succeeded.
0
+ # Exceptions are not propagated, except for SystemExit.
0
+ def report_app_init_status(channel)
0
+ channel.write('success')
0
rescue StandardError, ScriptError, NoMemoryError => e
0
if ENV['TESTING_PASSENGER'] == '1'
0
print_exception(self.class.to_s, e)
0
- client.write('exception')
0
- client.write_scalar(marshal_exception(e))
0
+ channel.write('exception')
0
+ channel.write_scalar(marshal_exception(e))
0
- client.write('success')
0
+ # Receive status information that was sent to _channel_ by
0
+ # report_app_init_status. If an error occured according to the
0
+ # received information, then an appropriate exception will be
0
+ # - IOError, SystemCallError, SocketError
0
+ def unmarshal_and_raise_errors(channel)
0
+ raise EOFError, "Unexpected end-of-file detected."
0
+ if status == 'exception'
0
+ child_exception = unmarshal_exception(channel.read_scalar)
0
+ raise AppInitError.new(
0
+ "Application '#{@app_root}' raised an exception: " <<
0
+ "#{child_exception.class} (#{child_exception.message})",
0
+ elsif status == 'exit'
0
+ raise AppInitError.new("Application '#{@app_root}' exited during startup")
0
+ # Lower the current process's privilege to the owner of config/environment.rb.
0
+ # No exceptions will be raised in the event that privilege lowering fails.
0
stat = File.stat("config/environment.rb")
Comments
No one has commented yet.