about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--Rakefile2
-rw-r--r--bin/mongrel_rails15
-rw-r--r--lib/mongrel.rb2
-rw-r--r--lib/mongrel/rails.rb21
4 files changed, 28 insertions, 12 deletions
diff --git a/Rakefile b/Rakefile
index cfde780..076a328 100644
--- a/Rakefile
+++ b/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"
diff --git a/bin/mongrel_rails b/bin/mongrel_rails
index 294a41c..bc2aac4 100644
--- a/bin/mongrel_rails
+++ b/bin/mongrel_rails
@@ -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
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 7bc9017..f135ca3 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -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"
diff --git a/lib/mongrel/rails.rb b/lib/mongrel/rails.rb
index e55e272..ecff187 100644
--- a/lib/mongrel/rails.rb
+++ b/lib/mongrel/rails.rb
@@ -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