1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Initial fix for some edge rails problems.

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@87 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
zedshaw 2006-03-08 00:52:20 +00:00
parent c24a58c9ab
commit 5bf3bca495
4 changed files with 28 additions and 12 deletions

View file

@ -31,7 +31,7 @@ end
setup_extension("http11", "http11") setup_extension("http11", "http11")
version="0.3.9" version="0.3.10"
summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps." summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps."
test_file = "test/test_ws.rb" test_file = "test/test_ws.rb"
author="Zed A. Shaw" author="Zed A. Shaw"

View file

@ -72,8 +72,13 @@ class Start < GemPlugin::Plugin "/commands"
end end
def configure_rails def configure_rails
# need this later for safe reloading
@orig_dollar_quote = $".clone
ENV['RAILS_ENV'] = @environment ENV['RAILS_ENV'] = @environment
require 'config/environment' require 'config/environment'
require 'dispatcher'
require 'cgi'
# configure the rails handler # configure the rails handler
rails = RailsHandler.new(@docroot, load_mime_map) rails = RailsHandler.new(@docroot, load_mime_map)
@ -87,9 +92,6 @@ class Start < GemPlugin::Plugin "/commands"
server = Mongrel::HttpServer.new(@address, @port, @num_procs.to_i, @timeout.to_i) server = Mongrel::HttpServer.new(@address, @port, @num_procs.to_i, @timeout.to_i)
server.register("/", rails) server.register("/", rails)
# start mongrel processing thread
server.run
# signal trapping just applies to posix systems # signal trapping just applies to posix systems
# TERM is a valid signal, but still doesn't gracefuly shutdown on win32. # TERM is a valid signal, but still doesn't gracefuly shutdown on win32.
if RUBY_PLATFORM !~ /mswin/ if RUBY_PLATFORM !~ /mswin/
@ -100,8 +102,9 @@ class Start < GemPlugin::Plugin "/commands"
# rails reload # rails reload
trap("HUP") { trap("HUP") {
server.stop STDERR.puts "Reloading rails..."
@restart = true rails.reload!
STDERR.puts "Done reloading rails."
} }
# restart # restart
@ -115,6 +118,8 @@ class Start < GemPlugin::Plugin "/commands"
GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE
begin begin
# start mongrel processing thread
server.run
STDERR.puts "Server ready." STDERR.puts "Server ready."
server.acceptor.join server.acceptor.join
rescue Interrupt rescue Interrupt

View file

@ -140,7 +140,7 @@ module Mongrel
SERVER_SOFTWARE='SERVER_SOFTWARE' SERVER_SOFTWARE='SERVER_SOFTWARE'
# Current Mongrel version (used for SERVER_SOFTWARE and other response headers). # Current Mongrel version (used for SERVER_SOFTWARE and other response headers).
MONGREL_VERSION='Mongrel 0.3.8' MONGREL_VERSION='Mongrel 0.3.10'
# The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff. # The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND" ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND"

View file

@ -1,5 +1,6 @@
require 'mongrel' require 'mongrel'
require_gem 'rails' require 'cgi'
# Implements a handler that can run Rails and serve files out of the # Implements a handler that can run Rails and serve files out of the
# Rails application's public directory. This lets you run your Rails # Rails application's public directory. This lets you run your Rails
@ -23,6 +24,7 @@ require_gem 'rails'
# An additional feature you can use is # An additional feature you can use is
class RailsHandler < Mongrel::HttpHandler class RailsHandler < Mongrel::HttpHandler
attr_reader :files attr_reader :files
attr_reader :guard
def initialize(dir, mime_map = {}) def initialize(dir, mime_map = {})
@files = Mongrel::DirHandler.new(dir,false) @files = Mongrel::DirHandler.new(dir,false)
@ -52,10 +54,10 @@ class RailsHandler < Mongrel::HttpHandler
request.params[Mongrel::Const::PATH_INFO] = page_cached request.params[Mongrel::Const::PATH_INFO] = page_cached
@files.process(request,response) @files.process(request,response)
else else
begin
cgi = Mongrel::CGIWrapper.new(request, response) cgi = Mongrel::CGIWrapper.new(request, response)
cgi.handler = self cgi.handler = self
begin
@guard.synchronize do @guard.synchronize do
# Rails is not thread safe so must be run entirely within synchronize # Rails is not thread safe so must be run entirely within synchronize
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body) Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
@ -72,4 +74,13 @@ class RailsHandler < Mongrel::HttpHandler
end end
end end
def reload!
@guard.synchronize do
$".replace @orig_dollar_quote
GC.start
Dispatcher.reset_application!
ActionController::Routing::Routes.reload
end
end
end end