Parent

Class/Module Index [+]

Quicksearch

PhusionPassenger::ClassicRails::ApplicationSpawner

Spawning of Rails 1 and Rails 2 applications.

ClassicRails::ApplicationSpawner can operate in two modes:

Attributes

app_root[R]

The application root of this spawner.

Public Class Methods

new(options) click to toggle source

The following options are accepted:

See SpawnManager#spawn_application for information about the options.

# File lib/phusion_passenger/classic_rails/application_spawner.rb, line 116
def initialize(options)
        super()
        @options          = sanitize_spawn_options(options)
        @app_root         = @options["app_root"]
        @canonicalized_app_root = canonicalize_path(@app_root)
        self.max_idle_time = DEFAULT_APP_SPAWNER_MAX_IDLE_TIME
        define_message_handler(:spawn_application, :handle_spawn_application)
end
spawn_application(options) click to toggle source

Spawns an instance of a Rails application. When successful, an AppProcess object will be returned, which represents the spawned Rails application.

This method spawns the application directly, without preloading its code. This method may only be called if no Rails framework has been loaded in the current Ruby VM.

The "app_root" option must be given. All other options are passed to the request handler's constructor.

Raises:

  • AppInitError: The Ruby on Rails application raised an exception or called exit() during startup.

  • SystemCallError, IOError, SocketError: Something went wrong.

# File lib/phusion_passenger/classic_rails/application_spawner.rb, line 80
def self.spawn_application(options)
        options = sanitize_spawn_options(options)
        
        a, b = UNIXSocket.pair
        pid = safe_fork('application', true) do
                a.close
                
                file_descriptors_to_leave_open = [0, 1, 2, b.fileno]
                NativeSupport.close_all_file_descriptors(file_descriptors_to_leave_open)
                close_all_io_objects_for_fds(file_descriptors_to_leave_open)
                
                channel = MessageChannel.new(b)
                success = report_app_init_status(channel) do
                        prepare_app_process('config/environment.rb', options)
                        require File.expand_path('config/environment')
                        require 'dispatcher'
                        after_loading_app_code(options)
                end
                if success
                        start_request_handler(channel, false, options)
                end
        end
        b.close
        Process.waitpid(pid) rescue nil
        
        channel = MessageChannel.new(a)
        unmarshal_and_raise_errors(channel, options["print_exceptions"])
        
        # No exception was raised, so spawning succeeded.
        return AppProcess.read_from_channel(channel)
end

Public Instance Methods

spawn_application(options = {}) click to toggle source

Spawns an instance of the Rails application. When successful, an AppProcess object will be returned, which represents the spawned Rails application.

options will be passed to the request handler's constructor.

Raises:

# File lib/phusion_passenger/classic_rails/application_spawner.rb, line 133
def spawn_application(options = {})
        connect do |channel|
                channel.write("spawn_application", *options.to_a.flatten)
                return AppProcess.read_from_channel(channel)
        end
rescue SystemCallError, IOError, SocketError => e
        raise Error, "The application spawner server exited unexpectedly: #{e}"
end
start() click to toggle source

Overrided from AbstractServer#start.

May raise these additional exceptions:

  • AppInitError: The Ruby on Rails application raised an exception or called exit() during startup.

  • ApplicationSpawner::Error: The ApplicationSpawner server exited unexpectedly.

# File lib/phusion_passenger/classic_rails/application_spawner.rb, line 148
def start
        super
        begin
                channel = MessageChannel.new(@owner_socket)
                unmarshal_and_raise_errors(channel, @options["print_exceptions"])
        rescue IOError, SystemCallError, SocketError => e
                stop if started?
                raise Error, "The application spawner server exited unexpectedly: #{e}"
        rescue
                stop if started?
                raise
        end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.