Browse files

Better support Ruby implementations that don't support native extensi…

…ons and forking.
  • Loading branch information...
1 parent f1dd98b commit 1bbe8cfd27db42c5b77d7ee5d2391bba3a9d0fa6 @FooBarWidget FooBarWidget committed Oct 26, 2012
View
4 helper-scripts/classic-rails-loader.rb
@@ -46,7 +46,9 @@ def self.init_passenger
LoaderSharedHelpers.init
@@options = LoaderSharedHelpers.sanitize_spawn_options(@@options)
Utils.passenger_tmpdir = options["generation_dir"]
- NativeSupport.disable_stdio_buffering
+ if defined?(NativeSupport)
+ NativeSupport.disable_stdio_buffering
+ end
rescue Exception => e
LoaderSharedHelpers.about_to_abort(e) if defined?(LoaderSharedHelpers)
puts "!> Error"
View
5 helper-scripts/classic-rails-preloader.rb
@@ -48,9 +48,12 @@ def self.init_passenger
require 'phusion_passenger/loader_shared_helpers'
require 'phusion_passenger/request_handler'
LoaderSharedHelpers.init
+ PreloaderSharedHelpers.init
@@options = LoaderSharedHelpers.sanitize_spawn_options(@@options)
Utils.passenger_tmpdir = options["generation_dir"]
- NativeSupport.disable_stdio_buffering
+ if defined?(NativeSupport)
+ NativeSupport.disable_stdio_buffering
+ end
rescue Exception => e
LoaderSharedHelpers.about_to_abort(e) if defined?(LoaderSharedHelpers)
puts "!> Error"
View
4 helper-scripts/rack-loader.rb
@@ -52,7 +52,9 @@ def self.init_passenger
LoaderSharedHelpers.init
@@options = LoaderSharedHelpers.sanitize_spawn_options(@@options)
Utils.passenger_tmpdir = options["generation_dir"]
- NativeSupport.disable_stdio_buffering
+ if defined?(NativeSupport)
+ NativeSupport.disable_stdio_buffering
+ end
RequestHandler::ThreadHandler.send(:include, Rack::ThreadHandlerExtension)
rescue Exception => e
LoaderSharedHelpers.about_to_abort(e) if defined?(LoaderSharedHelpers)
View
5 helper-scripts/rack-preloader.rb
@@ -53,9 +53,12 @@ def self.init_passenger
require 'phusion_passenger/request_handler'
require 'phusion_passenger/rack/thread_handler_extension'
LoaderSharedHelpers.init
+ PreloaderSharedHelpers.init
@@options = LoaderSharedHelpers.sanitize_spawn_options(@@options)
Utils.passenger_tmpdir = options["generation_dir"]
- NativeSupport.disable_stdio_buffering
+ if defined?(NativeSupport)
+ NativeSupport.disable_stdio_buffering
+ end
RequestHandler::ThreadHandler.send(:include, Rack::ThreadHandlerExtension)
rescue Exception => e
LoaderSharedHelpers.about_to_abort(e) if defined?(LoaderSharedHelpers)
View
13 lib/phusion_passenger/preloader_shared_helpers.rb
@@ -30,6 +30,19 @@ module PhusionPassenger
# Provides shared functions for preloader apps.
module PreloaderSharedHelpers
extend self
+
+ def init
+ if !Kernel.respond_to?(:fork)
+ message = "Smart spawning is not available on this Ruby " +
+ "implementation because it does not support `Kernel.fork`. "
+ if ENV['SERVER_SOFTWARE'].to_s =~ /nginx/i
+ message << "Please set `passenger_spawn_method` to `direct`."
+ else
+ message << "Please set `PassengerSpawnMethod` to `direct`."
+ end
+ raise(message)
+ end
+ end
def accept_and_process_next_client(server_socket)
original_pid = Process.pid
View
29 lib/phusion_passenger/ruby_core_enhancements.rb
@@ -77,6 +77,35 @@ def writev3(components, components2, components3)
return PhusionPassenger::NativeSupport.writev3(fileno,
components, components2, components3)
end
+ else
+ def writev(components)
+ return write(components.join(''))
+ end
+
+ def writev2(components, components2)
+ data = ''
+ components.each do |component|
+ data << component
+ end
+ components2.each do |component|
+ data << component
+ end
+ return write(data)
+ end
+
+ def writev3(components, components2, components3)
+ data = ''
+ components.each do |component|
+ data << component
+ end
+ components2.each do |component|
+ data << component
+ end
+ components3.each do |component|
+ data << component
+ end
+ return write(data)
+ end
end
if IO.method_defined?(:close_on_exec=)
View
2 lib/phusion_passenger/standalone/command.rb
@@ -34,7 +34,7 @@ class Command
:env => ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development',
:max_pool_size => 6,
:min_instances => 1,
- :spawn_method => 'smart',
+ :spawn_method => Kernel.respond_to?(:fork) ? 'smart' : 'direct',
:nginx_version => PREFERRED_NGINX_VERSION
}.freeze

0 comments on commit 1bbe8cf

Please sign in to comment.