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:
parent
c24a58c9ab
commit
5bf3bca495
4 changed files with 28 additions and 12 deletions
2
Rakefile
2
Rakefile
|
@ -31,7 +31,7 @@ end
|
|||
|
||||
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."
|
||||
test_file = "test/test_ws.rb"
|
||||
author="Zed A. Shaw"
|
||||
|
|
|
@ -72,8 +72,13 @@ class Start < GemPlugin::Plugin "/commands"
|
|||
end
|
||||
|
||||
def configure_rails
|
||||
# need this later for safe reloading
|
||||
@orig_dollar_quote = $".clone
|
||||
|
||||
ENV['RAILS_ENV'] = @environment
|
||||
require 'config/environment'
|
||||
require 'dispatcher'
|
||||
require 'cgi'
|
||||
|
||||
# configure the rails handler
|
||||
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.register("/", rails)
|
||||
|
||||
# start mongrel processing thread
|
||||
server.run
|
||||
|
||||
# signal trapping just applies to posix systems
|
||||
# TERM is a valid signal, but still doesn't gracefuly shutdown on win32.
|
||||
if RUBY_PLATFORM !~ /mswin/
|
||||
|
@ -100,8 +102,9 @@ class Start < GemPlugin::Plugin "/commands"
|
|||
|
||||
# rails reload
|
||||
trap("HUP") {
|
||||
server.stop
|
||||
@restart = true
|
||||
STDERR.puts "Reloading rails..."
|
||||
rails.reload!
|
||||
STDERR.puts "Done reloading rails."
|
||||
}
|
||||
|
||||
# restart
|
||||
|
@ -115,6 +118,8 @@ class Start < GemPlugin::Plugin "/commands"
|
|||
GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE
|
||||
|
||||
begin
|
||||
# start mongrel processing thread
|
||||
server.run
|
||||
STDERR.puts "Server ready."
|
||||
server.acceptor.join
|
||||
rescue Interrupt
|
||||
|
|
|
@ -140,7 +140,7 @@ module Mongrel
|
|||
SERVER_SOFTWARE='SERVER_SOFTWARE'
|
||||
|
||||
# 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.
|
||||
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'mongrel'
|
||||
require_gem 'rails'
|
||||
require 'cgi'
|
||||
|
||||
|
||||
# Implements a handler that can run Rails and serve files out of the
|
||||
# Rails application's public directory. This lets you run your Rails
|
||||
|
@ -23,7 +24,8 @@ require_gem 'rails'
|
|||
# An additional feature you can use is
|
||||
class RailsHandler < Mongrel::HttpHandler
|
||||
attr_reader :files
|
||||
|
||||
attr_reader :guard
|
||||
|
||||
def initialize(dir, mime_map = {})
|
||||
@files = Mongrel::DirHandler.new(dir,false)
|
||||
@guard = Mutex.new
|
||||
|
@ -52,10 +54,10 @@ class RailsHandler < Mongrel::HttpHandler
|
|||
request.params[Mongrel::Const::PATH_INFO] = page_cached
|
||||
@files.process(request,response)
|
||||
else
|
||||
cgi = Mongrel::CGIWrapper.new(request, response)
|
||||
cgi.handler = self
|
||||
|
||||
begin
|
||||
cgi = Mongrel::CGIWrapper.new(request, response)
|
||||
cgi.handler = self
|
||||
|
||||
@guard.synchronize do
|
||||
# Rails is not thread safe so must be run entirely within synchronize
|
||||
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
|
||||
|
@ -72,4 +74,13 @@ class RailsHandler < Mongrel::HttpHandler
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def reload!
|
||||
@guard.synchronize do
|
||||
$".replace @orig_dollar_quote
|
||||
GC.start
|
||||
Dispatcher.reset_application!
|
||||
ActionController::Routing::Routes.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue