mongrel 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/Rakefile +4 -2
  2. data/bin/mongrel_rails +65 -101
  3. data/bin/mongrel_rails_service +1 -1
  4. data/bin/mongrel_rails_svc +131 -115
  5. data/doc/rdoc/classes/Class.html +197 -0
  6. data/doc/rdoc/classes/Class.src/M000001.html +24 -0
  7. data/doc/rdoc/classes/Class.src/M000002.html +62 -0
  8. data/doc/rdoc/classes/Class.src/M000003.html +21 -0
  9. data/doc/rdoc/classes/Class.src/M000004.html +20 -0
  10. data/doc/rdoc/classes/IO.html +170 -0
  11. data/doc/rdoc/classes/IO.src/M000005.html +19 -0
  12. data/doc/rdoc/classes/IO.src/M000006.html +19 -0
  13. data/doc/rdoc/classes/Kernel.html +159 -0
  14. data/doc/rdoc/classes/Kernel.src/M000025.html +19 -0
  15. data/doc/rdoc/classes/Kernel.src/M000026.html +25 -0
  16. data/doc/rdoc/classes/Mongrel.html +181 -0
  17. data/doc/rdoc/classes/Mongrel/CGIWrapper.html +383 -0
  18. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000090.html +24 -0
  19. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000091.html +47 -0
  20. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000092.html +34 -0
  21. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000093.html +27 -0
  22. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000094.html +25 -0
  23. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000095.html +18 -0
  24. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000096.html +18 -0
  25. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000097.html +18 -0
  26. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000098.html +19 -0
  27. data/doc/rdoc/classes/Mongrel/Camping.html +177 -0
  28. data/doc/rdoc/classes/Mongrel/Camping.src/M000048.html +22 -0
  29. data/doc/rdoc/classes/Mongrel/Camping/CampingHandler.html +165 -0
  30. data/doc/rdoc/classes/Mongrel/Camping/CampingHandler.src/M000049.html +18 -0
  31. data/doc/rdoc/classes/Mongrel/Camping/CampingHandler.src/M000050.html +27 -0
  32. data/doc/rdoc/classes/Mongrel/Command.html +119 -0
  33. data/doc/rdoc/classes/Mongrel/Command/Base.html +337 -0
  34. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000029.html +24 -0
  35. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000030.html +41 -0
  36. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000031.html +18 -0
  37. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000032.html +18 -0
  38. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000033.html +18 -0
  39. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000034.html +22 -0
  40. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000035.html +18 -0
  41. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000036.html +18 -0
  42. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000037.html +18 -0
  43. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000038.html +18 -0
  44. data/doc/rdoc/classes/Mongrel/Command/Registry.html +192 -0
  45. data/doc/rdoc/classes/Mongrel/Command/Registry.src/M000039.html +20 -0
  46. data/doc/rdoc/classes/Mongrel/Command/Registry.src/M000040.html +25 -0
  47. data/doc/rdoc/classes/Mongrel/Command/Registry.src/M000041.html +46 -0
  48. data/doc/rdoc/classes/Mongrel/Configurator.html +563 -0
  49. data/doc/rdoc/classes/Mongrel/Configurator.src/M000099.html +24 -0
  50. data/doc/rdoc/classes/Mongrel/Configurator.src/M000100.html +23 -0
  51. data/doc/rdoc/classes/Mongrel/Configurator.src/M000101.html +18 -0
  52. data/doc/rdoc/classes/Mongrel/Configurator.src/M000102.html +32 -0
  53. data/doc/rdoc/classes/Mongrel/Configurator.src/M000103.html +19 -0
  54. data/doc/rdoc/classes/Mongrel/Configurator.src/M000104.html +31 -0
  55. data/doc/rdoc/classes/Mongrel/Configurator.src/M000105.html +33 -0
  56. data/doc/rdoc/classes/Mongrel/Configurator.src/M000106.html +18 -0
  57. data/doc/rdoc/classes/Mongrel/Configurator.src/M000107.html +25 -0
  58. data/doc/rdoc/classes/Mongrel/Configurator.src/M000108.html +19 -0
  59. data/doc/rdoc/classes/Mongrel/Configurator.src/M000109.html +22 -0
  60. data/doc/rdoc/classes/Mongrel/Configurator.src/M000110.html +21 -0
  61. data/doc/rdoc/classes/Mongrel/Configurator.src/M000111.html +18 -0
  62. data/doc/rdoc/classes/Mongrel/Configurator.src/M000112.html +27 -0
  63. data/doc/rdoc/classes/Mongrel/Configurator.src/M000113.html +46 -0
  64. data/doc/rdoc/classes/Mongrel/Configurator.src/M000114.html +18 -0
  65. data/doc/rdoc/classes/Mongrel/Const.html +286 -0
  66. data/doc/rdoc/classes/Mongrel/DirHandler.html +288 -0
  67. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000058.html +20 -0
  68. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000059.html +42 -0
  69. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000060.html +40 -0
  70. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000061.html +51 -0
  71. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000062.html +40 -0
  72. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000063.html +18 -0
  73. data/doc/rdoc/classes/Mongrel/Error404Handler.html +171 -0
  74. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000115.html +18 -0
  75. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000116.html +18 -0
  76. data/doc/rdoc/classes/Mongrel/HeaderOut.html +185 -0
  77. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000072.html +18 -0
  78. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000073.html +18 -0
  79. data/doc/rdoc/classes/Mongrel/HttpHandler.html +152 -0
  80. data/doc/rdoc/classes/Mongrel/HttpHandler.src/M000074.html +17 -0
  81. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.html +169 -0
  82. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.src/M000027.html +18 -0
  83. data/doc/rdoc/classes/Mongrel/HttpHandlerPlugin.src/M000028.html +17 -0
  84. data/doc/rdoc/classes/Mongrel/HttpParser.html +271 -0
  85. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000051.html +28 -0
  86. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000052.html +29 -0
  87. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000053.html +29 -0
  88. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000054.html +41 -0
  89. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000055.html +27 -0
  90. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000056.html +27 -0
  91. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000057.html +28 -0
  92. data/doc/rdoc/classes/Mongrel/HttpRequest.html +222 -0
  93. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000117.html +28 -0
  94. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000118.html +20 -0
  95. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000119.html +20 -0
  96. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000120.html +32 -0
  97. data/doc/rdoc/classes/Mongrel/HttpResponse.html +371 -0
  98. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000075.html +26 -0
  99. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000076.html +20 -0
  100. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000077.html +25 -0
  101. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000078.html +22 -0
  102. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000079.html +22 -0
  103. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000080.html +23 -0
  104. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000081.html +18 -0
  105. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000082.html +20 -0
  106. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000083.html +18 -0
  107. data/doc/rdoc/classes/Mongrel/HttpServer.html +360 -0
  108. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000064.html +24 -0
  109. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000065.html +65 -0
  110. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000066.html +24 -0
  111. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000067.html +60 -0
  112. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000068.html +28 -0
  113. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000069.html +18 -0
  114. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000070.html +22 -0
  115. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000071.html +18 -0
  116. data/doc/rdoc/classes/Mongrel/Rails.html +112 -0
  117. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.html +223 -0
  118. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.src/M000042.html +35 -0
  119. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.src/M000043.html +25 -0
  120. data/doc/rdoc/classes/Mongrel/Rails/RailsConfigurator.src/M000044.html +32 -0
  121. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.html +250 -0
  122. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.src/M000045.html +22 -0
  123. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.src/M000046.html +48 -0
  124. data/doc/rdoc/classes/Mongrel/Rails/RailsHandler.src/M000047.html +23 -0
  125. data/doc/rdoc/classes/Mongrel/StopServer.html +117 -0
  126. data/doc/rdoc/classes/Mongrel/URIClassifier.html +301 -0
  127. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000084.html +18 -0
  128. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000085.html +18 -0
  129. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000086.html +39 -0
  130. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000087.html +51 -0
  131. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000088.html +36 -0
  132. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000089.html +83 -0
  133. data/doc/rdoc/classes/MongrelDbg.html +209 -0
  134. data/doc/rdoc/classes/MongrelDbg.src/M000020.html +19 -0
  135. data/doc/rdoc/classes/MongrelDbg.src/M000021.html +20 -0
  136. data/doc/rdoc/classes/MongrelDbg.src/M000022.html +22 -0
  137. data/doc/rdoc/classes/MongrelDbg.src/M000023.html +21 -0
  138. data/doc/rdoc/classes/MongrelDbg.src/M000024.html +18 -0
  139. data/doc/rdoc/classes/ObjectTracker.html +176 -0
  140. data/doc/rdoc/classes/ObjectTracker.src/M000016.html +22 -0
  141. data/doc/rdoc/classes/ObjectTracker.src/M000017.html +18 -0
  142. data/doc/rdoc/classes/ObjectTracker.src/M000018.html +18 -0
  143. data/doc/rdoc/classes/ObjectTracker.src/M000019.html +46 -0
  144. data/doc/rdoc/classes/RequestLog.html +113 -0
  145. data/doc/rdoc/classes/RequestLog/Files.html +144 -0
  146. data/doc/rdoc/classes/RequestLog/Files.src/M000121.html +19 -0
  147. data/doc/rdoc/classes/RequestLog/Objects.html +144 -0
  148. data/doc/rdoc/classes/RequestLog/Objects.src/M000122.html +19 -0
  149. data/doc/rdoc/classes/RequestLog/Params.html +144 -0
  150. data/doc/rdoc/classes/RequestLog/Params.src/M000123.html +19 -0
  151. data/doc/rdoc/classes/Stats.html +306 -0
  152. data/doc/rdoc/classes/Stats.src/M000009.html +19 -0
  153. data/doc/rdoc/classes/Stats.src/M000010.html +23 -0
  154. data/doc/rdoc/classes/Stats.src/M000011.html +26 -0
  155. data/doc/rdoc/classes/Stats.src/M000012.html +18 -0
  156. data/doc/rdoc/classes/Stats.src/M000013.html +18 -0
  157. data/doc/rdoc/classes/Stats.src/M000014.html +19 -0
  158. data/doc/rdoc/classes/Stats.src/M000015.html +20 -0
  159. data/doc/rdoc/classes/TCPServer.html +173 -0
  160. data/doc/rdoc/classes/TCPServer.src/M000007.html +19 -0
  161. data/doc/rdoc/created.rid +1 -0
  162. data/doc/rdoc/files/COPYING.html +756 -0
  163. data/doc/rdoc/files/LICENSE.html +756 -0
  164. data/doc/rdoc/files/README.html +302 -0
  165. data/doc/rdoc/files/ext/http11/http11_c.html +101 -0
  166. data/doc/rdoc/files/lib/mongrel/camping_rb.html +108 -0
  167. data/doc/rdoc/files/lib/mongrel/cgi_rb.html +108 -0
  168. data/doc/rdoc/files/lib/mongrel/command_rb.html +111 -0
  169. data/doc/rdoc/files/lib/mongrel/debug_rb.html +110 -0
  170. data/doc/rdoc/files/lib/mongrel/handlers_rb.html +109 -0
  171. data/doc/rdoc/files/lib/mongrel/init_rb.html +109 -0
  172. data/doc/rdoc/files/lib/mongrel/rails_rb.html +111 -0
  173. data/doc/rdoc/files/lib/mongrel/stats_rb.html +117 -0
  174. data/doc/rdoc/files/lib/mongrel/tcphack_rb.html +109 -0
  175. data/doc/rdoc/files/lib/mongrel_rb.html +118 -0
  176. data/doc/rdoc/fr_class_index.html +60 -0
  177. data/doc/rdoc/fr_file_index.html +40 -0
  178. data/doc/rdoc/fr_method_index.html +149 -0
  179. data/doc/rdoc/index.html +24 -0
  180. data/doc/rdoc/rdoc-style.css +208 -0
  181. data/examples/builder.rb +29 -0
  182. data/examples/camping/blog.rb +11 -2
  183. data/examples/simpletest.rb +20 -7
  184. data/ext/http11/http11.c +71 -14
  185. data/ext/http11/http11_parser.c +27 -24
  186. data/ext/http11/http11_parser.h +2 -1
  187. data/lib/http11.bundle +0 -0
  188. data/lib/mongrel.rb +498 -135
  189. data/lib/mongrel/command.rb +1 -1
  190. data/lib/mongrel/debug.rb +259 -0
  191. data/lib/mongrel/handlers.rb +76 -22
  192. data/lib/mongrel/rails.rb +165 -72
  193. data/lib/mongrel/stats.rb +71 -0
  194. data/test/test_configurator.rb +67 -0
  195. data/test/test_debug.rb +31 -0
  196. data/test/test_http11.rb +16 -0
  197. data/test/test_response.rb +5 -0
  198. data/test/test_stats.rb +28 -0
  199. metadata +224 -2
data/Rakefile CHANGED
@@ -32,7 +32,7 @@ end
32
32
  setup_extension("http11", "http11")
33
33
 
34
34
  name="mongrel"
35
- version="0.3.11"
35
+ version="0.3.12"
36
36
 
37
37
  setup_gem(name, version) do |spec|
38
38
  spec.summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps."
@@ -65,7 +65,7 @@ task :package_win32 do
65
65
  spec.required_ruby_version = '>= 1.8.4'
66
66
 
67
67
  spec.add_dependency('win32-service', '>= 0.5.0')
68
- spec.add_dependency('gem_plugin', ">= 0.2")
68
+ spec.add_dependency('gem_plugin', ">= 0.2.1")
69
69
 
70
70
  spec.extensions = []
71
71
  spec.platform = Gem::Platform::WIN32
@@ -79,11 +79,13 @@ task :install do
79
79
  sh %{sudo gem install pkg/mongrel-#{version}}
80
80
  sub_project("mongrel_status", :install)
81
81
  sub_project("mongrel_config", :install)
82
+ sub_project("mongrel_console", :install)
82
83
  end
83
84
 
84
85
  task :uninstall => [:clean] do
85
86
  sub_project("mongrel_status", :uninstall)
86
87
  sub_project("mongrel_config", :uninstall)
88
+ sub_project("mongrel_console", :uninstall)
87
89
  sh %{sudo gem uninstall mongrel}
88
90
  sub_project("gem_plugin", :uninstall)
89
91
  end
@@ -1,6 +1,8 @@
1
+
1
2
  require 'rubygems'
2
3
  require 'yaml'
3
- require 'mongrel'
4
+ require 'mongrel/rails'
5
+
4
6
 
5
7
 
6
8
  class Start < GemPlugin::Plugin "/commands"
@@ -14,11 +16,13 @@ class Start < GemPlugin::Plugin "/commands"
14
16
  ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
15
17
  ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
16
18
  ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
17
- ['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, 20],
18
- ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, 120],
19
+ ['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, 1024],
20
+ ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, 0],
19
21
  ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
20
22
  ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
21
23
  ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
24
+ ['-B', '--debug', "Enable debugging mode", :@debug, false],
25
+ ['-C', '--config PATH', "Use a config file", :@config_file, nil]
22
26
  ]
23
27
  end
24
28
 
@@ -33,119 +37,72 @@ class Start < GemPlugin::Plugin "/commands"
33
37
  valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file"
34
38
  valid_dir? @docroot, "Path to docroot not valid: #@docroot"
35
39
  valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
36
-
40
+ valid_exists? @config_file, "Config file not there: #@config_file" if @config_file
37
41
  return @valid
38
42
  end
39
43
 
44
+ def run
40
45
 
41
- def daemonize
42
- # save this for later since daemonize will hose it
43
- if @daemon and RUBY_PLATFORM !~ /mswin/
44
- require 'daemons/daemonize'
45
-
46
- puts "Started Mongrel server in #@environment mode at #@address:#@port"
47
- Daemonize.daemonize(log_file=File.join(@cwd, @log_file))
48
-
49
- # change back to the original starting directory
50
- Dir.chdir(@cwd)
51
-
52
- open(@pid_file,"w") {|f| f.write(Process.pid) }
53
- else
54
- puts "Running Mongrel server in #@environment mode at #@address:#@port"
55
- end
56
- end
57
-
58
- def load_mime_map
59
- mime = {}
60
-
61
- # configure any requested mime map
62
- if @mime_map
63
- puts "Loading additional MIME types from #@mime_map"
64
- mime.merge!(YAML.load_file(@mime_map))
65
-
66
- # check all the mime types to make sure they are the right format
67
- mime.each {|k,v| puts "WARNING: MIME type #{k} must start with '.'" if k.index(".") != 0 }
46
+ # command line setting override config file settings
47
+ settings = { :host => @address, :port => @port, :cwd => @cwd,
48
+ :log_file => @log_file, :pid_file => @pid_file, :environment => @environment,
49
+ :docroot => @docroot, :mime_map => @mime_map, :daemon => @daemon,
50
+ :debug => @debug, :includes => ["mongrel"]
51
+ }
52
+
53
+ if @config_file
54
+ STDERR.puts "** Loading settings from #{@config_file} (command line options override)."
55
+ conf = YAML.load_file(@config_file)
56
+ settings = conf.merge(settings)
68
57
  end
69
58
 
70
- return mime
71
- end
72
-
73
- def configure_rails
74
- # need this later for safe reloading
75
- $orig_dollar_quote = $".clone
76
-
77
- ENV['RAILS_ENV'] = @environment
78
- require 'config/environment'
79
- require 'dispatcher'
80
- require 'mongrel/rails'
81
-
82
- # configure the rails handler
83
- rails = RailsHandler.new(@docroot, load_mime_map)
84
-
85
- return rails
86
- end
87
-
88
- def start_mongrel(rails)
89
- @restart = false
90
-
91
- server = Mongrel::HttpServer.new(@address, @port, @num_procs.to_i, @timeout.to_i)
92
- server.register("/", rails)
93
-
94
- # signal trapping just applies to posix systems
95
- # TERM is a valid signal, but still doesn't gracefuly shutdown on win32.
96
- if RUBY_PLATFORM !~ /mswin/
97
- # graceful shutdown
98
- trap("TERM") {
99
- server.stop
100
- File.unlink @pid_file if File.exist?(@pid_file)
101
- }
102
-
103
- # rails reload
104
- trap("HUP") {
105
- STDERR.puts "Reloading rails..."
106
- rails.reload!
107
- STDERR.puts "Done reloading rails."
108
- }
109
-
110
- # restart
111
- trap("USR2") {
112
- server.stop
113
- File.unlink @pid_file if File.exist?(@pid_file)
114
- @restart = true
115
- }
59
+ config = Mongrel::Rails::RailsConfigurator.new(settings) do
60
+ log "Starting Mongrel in #{settings[:environment]} mode at #{settings[:host]}:#{settings[:port]}"
61
+
62
+ if defaults[:daemon]
63
+ log "Daemonizing, any open files are closed. Look at #{settings[:pid_file]} and #{settings[:log_file]} for info."
64
+ daemonize
65
+ end
66
+
67
+ listener do
68
+ mime = {}
69
+ if defaults[:mime_map]
70
+ log "Loading additional MIME types from #{settings[:mime_map]}"
71
+ mime = load_mime_map(defaults[:mime_map], mime)
72
+ end
73
+
74
+ if defaults[:debug]
75
+ log "Installing debugging prefixed filters. Look in log/mongrel_debug for the files."
76
+ debug "/"
77
+ end
78
+
79
+ log "Starting Rails in environment #{settings[:environment]} ..."
80
+ uri "/", :handler => rails
81
+ log "Rails loaded."
82
+
83
+ log "Loading any Rails specific GemPlugins"
84
+ load_plugins
85
+
86
+ setup_rails_signals
87
+ end
116
88
  end
117
89
 
118
- # hook up any rails specific plugins
119
- GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE
120
-
121
- begin
122
- # start mongrel processing thread
123
- server.run
90
+ config.run
91
+ config.log "Mongrel available at #{settings[:host]}:#{settings[:port]}"
92
+ config.join
124
93
 
94
+ if config.needs_restart
125
95
  if RUBY_PLATFORM !~ /mswin/
126
- puts "Server Ready. Use CTRL-C to quit."
96
+ cmd = "ruby #{__FILE__} start #{original_args.join(' ')}"
97
+ config.log "Restarting with arguments: #{cmd}"
98
+ exec cmd
127
99
  else
128
- puts "Server Ready. Use CTRL-Pause/Break to quit."
100
+ config.log "Win32 does not support restarts. Exiting."
129
101
  end
130
-
131
- server.acceptor.join
132
- rescue Interrupt
133
- STDERR.puts "Interrupted."
134
- raise
135
102
  end
136
-
137
- # daemonize makes restart easy
138
- run if @restart
139
- end
140
-
141
- def run
142
- daemonize
143
- rails = configure_rails
144
- start_mongrel(rails)
145
103
  end
146
104
  end
147
105
 
148
-
149
106
  def send_signal(signal, pid_file)
150
107
  pid = open(pid_file).read.to_i
151
108
  print "Sending #{signal} to Mongrel at PID #{pid}..."
@@ -223,6 +180,13 @@ class Restart < GemPlugin::Plugin "/commands"
223
180
  end
224
181
  end
225
182
 
183
+
226
184
  GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE
227
185
 
228
- Mongrel::Command::Registry.instance.run ARGV
186
+
187
+ if not Mongrel::Command::Registry.instance.run ARGV
188
+ exit 1
189
+ end
190
+
191
+
192
+
@@ -80,7 +80,7 @@ class Install < GemPlugin::Plugin "/commands"
80
80
  end
81
81
 
82
82
  # Expand to get full path for mime-types file
83
- @mime_map = File.Expand_path(@mime_map) if @mime_map
83
+ @mime_map = File.expand_path(@mime_map) if @mime_map
84
84
 
85
85
  # default service display to service name
86
86
  @svc_display = @svc_name if !@svc_display
@@ -4,6 +4,7 @@
4
4
  # This is where Win32::Daemon resides.
5
5
  ###############################################
6
6
  require 'rubygems'
7
+ require 'mongrel'
7
8
  require 'mongrel/rails'
8
9
  require 'optparse'
9
10
  require 'win32/service'
@@ -70,14 +71,15 @@ class MongrelRails
70
71
 
71
72
  def delayed_initialize
72
73
  dbg "delayed_initialize entered"
73
-
74
+
74
75
  @rails = configure_rails
75
76
 
76
77
  # start up mongrel with the right configurations
77
78
  @server = Mongrel::HttpServer.new(@ip, @port, @num_procs.to_i, @timeout.to_i)
78
79
  @server.register("/", @rails)
79
-
80
+
80
81
  dbg "delayed_initialize left"
82
+
81
83
  end
82
84
 
83
85
  def load_mime_map
@@ -104,11 +106,12 @@ class MongrelRails
104
106
 
105
107
  Dir.chdir(@rails_root)
106
108
 
109
+
107
110
  ENV['RAILS_ENV'] = @environment
108
- require File.join(@rails_root, 'config/environment')
111
+ require 'config/environment'
109
112
 
110
113
  # configure the rails handler
111
- rails = RailsHandler.new(@docroot, load_mime_map)
114
+ rails = Mongrel::Rails::RailsHandler.new(@docroot, load_mime_map)
112
115
 
113
116
  dbg "configure_rails left"
114
117
 
@@ -116,24 +119,29 @@ class MongrelRails
116
119
  end
117
120
 
118
121
  def start_serve
119
- dbg "start_serve entered"
120
-
121
- @runner = Thread.new do
122
- dbg_th "runner_thread suspended"
123
- Thread.stop
122
+ begin
123
+ dbg "start_serve entered"
124
+
125
+ @runner = Thread.new do
126
+ dbg_th "runner_thread suspended"
127
+ Thread.stop
128
+
129
+ dbg_th "runner_thread resumed"
130
+ dbg_th "runner_thread acceptor.join"
131
+ @server.acceptor.join
132
+ end
124
133
 
125
- dbg_th "runner_thread resumed"
126
- dbg_th "runner_thread acceptor.join"
127
- @server.acceptor.join
134
+ dbg "server.run"
135
+ @server.run
136
+
137
+ dbg "runner.run"
138
+ @runner.run
139
+
140
+ dbg "start_serve left"
141
+ rescue
142
+ dbg "ERROR: #$!\r\n"
143
+ dbg $!.backtrace.join("\r\n")
128
144
  end
129
-
130
- dbg "server.run"
131
- @server.run
132
-
133
- dbg "runner.run"
134
- @runner.run
135
-
136
- dbg "start_serve left"
137
145
  end
138
146
 
139
147
  def stop_serve
@@ -193,99 +201,107 @@ class RailsDaemon < Win32::Daemon
193
201
  end
194
202
 
195
203
 
196
- if ARGV[0] == 'service'
197
- ARGV.shift
198
-
199
- # default options
200
- OPTIONS = {
201
- :rails_root => Dir.pwd,
202
- :environment => 'production',
203
- :ip => '0.0.0.0',
204
- :port => 3000,
205
- :mime_map => nil,
206
- :num_procs => 20,
207
- :timeout => 120,
208
- :cpu => nil
209
- }
210
-
211
- ARGV.options do |opts|
212
- opts.on('-r', '--root PATH', "Set the root path where your rails app resides.") { |OPTIONS[:rails_root]| }
213
- opts.on('-e', '--environment ENV', "Rails environment to run as. (default: production)") { |OPTIONS[:environment]| }
214
- opts.on('-b', '--binding ADDR', "Address to bind to") { |OPTIONS[:ip]| }
215
- opts.on('-p', '--port PORT', "Which port to bind to") { |OPTIONS[:port]| }
216
- opts.on('-m', '--mime PATH', "A YAML file that lists additional MIME types") { |OPTIONS[:mime_map]| }
217
- opts.on('-P', '--num-procs INT', "Number of processor threads to use") { |OPTIONS[:num_procs]| }
218
- opts.on('-t', '--timeout SECONDS', "Timeout all requests after SECONDS time") { |OPTIONS[:timeout]| }
219
- opts.on('-c', '--cpu CPU', "Bind the process to specific cpu") { |OPTIONS[:cpu]| }
220
-
221
- opts.parse!
222
- end
223
-
224
- #expand RAILS_ROOT
225
- OPTIONS[:rails_root] = File.expand_path(OPTIONS[:rails_root])
226
-
227
- OPTIONS[:docroot] = File.expand_path(OPTIONS[:rails_root] + '/public')
228
-
229
- # We must bind to a specific cpu?
230
- if OPTIONS[:cpu]
231
- Kernel32.set_affinity(Process.pid, OPTIONS[:cpu])
232
- end
233
-
234
- rails = MongrelRails.new(OPTIONS[:ip], OPTIONS[:port], OPTIONS[:rails_root], OPTIONS[:docroot], OPTIONS[:environment], OPTIONS[:mime_map], OPTIONS[:num_procs].to_i, OPTIONS[:timeout].to_i)
235
- rails_svc = RailsDaemon.new(rails)
236
- rails_svc.mainloop
237
-
238
- elsif ARGV[0] == 'debug'
239
- ARGV.shift
240
-
241
- # default options
242
- OPTIONS = {
243
- :rails_root => Dir.pwd,
244
- :environment => 'production',
245
- :ip => '0.0.0.0',
246
- :port => 3000,
247
- :mime_map => nil,
248
- :num_procs => 20,
249
- :timeout => 120,
250
- :cpu => nil
251
- }
252
-
253
- ARGV.options do |opts|
254
- opts.on('-r', '--root PATH', "Set the root path where your rails app resides.") { |OPTIONS[:rails_root]| }
255
- opts.on('-e', '--environment ENV', "Rails environment to run as.") { |OPTIONS[:environment]| }
256
- opts.on('-b', '--binding ADDR', "Address to bind to") { |OPTIONS[:ip]| }
257
- opts.on('-p', '--port PORT', "Which port to bind to") { |OPTIONS[:port]| }
258
- opts.on('-m', '--mime PATH', "A YAML file that lists additional MIME types") { |OPTIONS[:mime_map]| }
259
- opts.on('-P', '--num-procs INT', "Number of processor threads to use") { |OPTIONS[:num_procs]| }
260
- opts.on('-t', '--timeout SECONDS', "Timeout all requests after SECONDS time") { |OPTIONS[:timeout]| }
261
- opts.on('-c', '--cpu CPU', "Bind the process to specific cpu") { |OPTIONS[:cpu]| }
262
-
263
- opts.parse!
264
- end
265
-
266
- #expand RAILS_ROOT
267
- OPTIONS[:rails_root] = File.expand_path(OPTIONS[:rails_root])
268
-
269
- OPTIONS[:docroot] = File.expand_path(OPTIONS[:rails_root] + '/public')
270
-
271
- # We must bind to a specific cpu?
272
- if OPTIONS[:cpu]
273
- Kernel32.set_affinity(Process.pid, OPTIONS[:cpu])
274
- end
275
-
276
- rails = MongrelRails.new(OPTIONS[:ip], OPTIONS[:port], OPTIONS[:rails_root], OPTIONS[:docroot], OPTIONS[:environment], OPTIONS[:mime_map], OPTIONS[:num_procs].to_i, OPTIONS[:timeout].to_i)
277
- rails.delayed_initialize
278
- rails.start_serve
279
-
280
- begin
281
- sleep
282
- rescue Interrupt
283
- puts "graceful shutdown?"
284
- end
285
-
286
- begin
287
- rails.stop_serve
288
- rescue
289
- end
290
-
204
+ begin
205
+ if ARGV[0] == 'service'
206
+ ARGV.shift
207
+
208
+ # default options
209
+ OPTIONS = {
210
+ :rails_root => Dir.pwd,
211
+ :environment => 'production',
212
+ :ip => '0.0.0.0',
213
+ :port => 3000,
214
+ :mime_map => nil,
215
+ :num_procs => 1024,
216
+ :timeout => 0,
217
+ :cpu => nil
218
+ }
219
+
220
+ ARGV.options do |opts|
221
+ opts.on('-r', '--root PATH', "Set the root path where your rails app resides.") { |OPTIONS[:rails_root]| }
222
+ opts.on('-e', '--environment ENV', "Rails environment to run as. (default: production)") { |OPTIONS[:environment]| }
223
+ opts.on('-b', '--binding ADDR', "Address to bind to") { |OPTIONS[:ip]| }
224
+ opts.on('-p', '--port PORT', "Which port to bind to") { |OPTIONS[:port]| }
225
+ opts.on('-m', '--mime PATH', "A YAML file that lists additional MIME types") { |OPTIONS[:mime_map]| }
226
+ opts.on('-P', '--num-procs INT', "Number of processor threads to use") { |OPTIONS[:num_procs]| }
227
+ opts.on('-t', '--timeout SECONDS', "Timeout all requests after SECONDS time") { |OPTIONS[:timeout]| }
228
+ opts.on('-c', '--cpu CPU', "Bind the process to specific cpu") { |OPTIONS[:cpu]| }
229
+
230
+ opts.parse!
231
+ end
232
+
233
+ #expand RAILS_ROOT
234
+ OPTIONS[:rails_root] = File.expand_path(OPTIONS[:rails_root])
235
+
236
+ OPTIONS[:docroot] = File.expand_path(OPTIONS[:rails_root] + '/public')
237
+
238
+ # We must bind to a specific cpu?
239
+ if OPTIONS[:cpu]
240
+ Kernel32.set_affinity(Process.pid, OPTIONS[:cpu])
241
+ end
242
+
243
+ rails = MongrelRails.new(OPTIONS[:ip], OPTIONS[:port], OPTIONS[:rails_root], OPTIONS[:docroot], OPTIONS[:environment], OPTIONS[:mime_map], OPTIONS[:num_procs].to_i, OPTIONS[:timeout].to_i)
244
+ rails_svc = RailsDaemon.new(rails)
245
+ rails_svc.mainloop
246
+
247
+ elsif ARGV[0] == 'debug'
248
+ ARGV.shift
249
+
250
+ # default options
251
+ OPTIONS = {
252
+ :rails_root => Dir.pwd,
253
+ :environment => 'production',
254
+ :ip => '0.0.0.0',
255
+ :port => 3000,
256
+ :mime_map => nil,
257
+ :num_procs => 20,
258
+ :timeout => 120,
259
+ :cpu => nil
260
+ }
261
+
262
+ ARGV.options do |opts|
263
+ opts.on('-r', '--root PATH', "Set the root path where your rails app resides.") { |OPTIONS[:rails_root]| }
264
+ opts.on('-e', '--environment ENV', "Rails environment to run as.") { |OPTIONS[:environment]| }
265
+ opts.on('-b', '--binding ADDR', "Address to bind to") { |OPTIONS[:ip]| }
266
+ opts.on('-p', '--port PORT', "Which port to bind to") { |OPTIONS[:port]| }
267
+ opts.on('-m', '--mime PATH', "A YAML file that lists additional MIME types") { |OPTIONS[:mime_map]| }
268
+ opts.on('-P', '--num-procs INT', "Number of processor threads to use") { |OPTIONS[:num_procs]| }
269
+ opts.on('-t', '--timeout SECONDS', "Timeout all requests after SECONDS time") { |OPTIONS[:timeout]| }
270
+ opts.on('-c', '--cpu CPU', "Bind the process to specific cpu") { |OPTIONS[:cpu]| }
271
+
272
+ opts.parse!
273
+ end
274
+
275
+ #expand RAILS_ROOT
276
+ OPTIONS[:rails_root] = File.expand_path(OPTIONS[:rails_root])
277
+
278
+ OPTIONS[:docroot] = File.expand_path(OPTIONS[:rails_root] + '/public')
279
+
280
+ # We must bind to a specific cpu?
281
+ if OPTIONS[:cpu]
282
+ Kernel32.set_affinity(Process.pid, OPTIONS[:cpu])
283
+ end
284
+
285
+ rails = MongrelRails.new(OPTIONS[:ip], OPTIONS[:port], OPTIONS[:rails_root], OPTIONS[:docroot], OPTIONS[:environment], OPTIONS[:mime_map], OPTIONS[:num_procs].to_i, OPTIONS[:timeout].to_i)
286
+ rails.delayed_initialize
287
+ rails.start_serve
288
+
289
+ begin
290
+ sleep
291
+ rescue Interrupt
292
+ dbg "ERROR: #$!\r\n"
293
+ dbg $!.backtrace.join("\r\n")
294
+ puts "graceful shutdown?"
295
+ end
296
+
297
+ begin
298
+ rails.stop_serve
299
+ rescue
300
+ dbg "ERROR: #$!\r\n"
301
+ dbg $!.backtrace.join("\r\n")
302
+ end
303
+ end
304
+ rescue
305
+ dbg "ERROR: #$!\r\n"
306
+ dbg $!.backtrace.join("\r\n")
291
307
  end