rails 2.3.18 → 7.1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +2 -2
  3. data/README.md +97 -0
  4. metadata +207 -332
  5. data/CHANGELOG +0 -2193
  6. data/README +0 -243
  7. data/Rakefile +0 -365
  8. data/bin/about +0 -4
  9. data/bin/console +0 -3
  10. data/bin/dbconsole +0 -3
  11. data/bin/destroy +0 -3
  12. data/bin/generate +0 -3
  13. data/bin/performance/benchmarker +0 -3
  14. data/bin/performance/profiler +0 -3
  15. data/bin/plugin +0 -3
  16. data/bin/rails +0 -21
  17. data/bin/runner +0 -3
  18. data/bin/server +0 -3
  19. data/builtin/rails_info/rails/info.rb +0 -131
  20. data/builtin/rails_info/rails/info_controller.rb +0 -9
  21. data/builtin/rails_info/rails/info_helper.rb +0 -2
  22. data/builtin/rails_info/rails_info_controller.rb +0 -2
  23. data/configs/databases/frontbase.yml +0 -28
  24. data/configs/databases/ibm_db.yml +0 -62
  25. data/configs/databases/mysql.yml +0 -60
  26. data/configs/databases/oracle.yml +0 -39
  27. data/configs/databases/postgresql.yml +0 -51
  28. data/configs/databases/sqlite2.yml +0 -19
  29. data/configs/databases/sqlite3.yml +0 -22
  30. data/configs/empty.log +0 -0
  31. data/configs/initializers/backtrace_silencers.rb +0 -7
  32. data/configs/initializers/cookie_verification_secret.rb +0 -7
  33. data/configs/initializers/inflections.rb +0 -10
  34. data/configs/initializers/mime_types.rb +0 -5
  35. data/configs/initializers/new_rails_defaults.rb +0 -21
  36. data/configs/initializers/session_store.rb +0 -15
  37. data/configs/locales/en.yml +0 -5
  38. data/configs/routes.rb +0 -43
  39. data/configs/seeds.rb +0 -7
  40. data/dispatches/config.ru +0 -7
  41. data/dispatches/dispatch.fcgi +0 -24
  42. data/dispatches/dispatch.rb +0 -10
  43. data/dispatches/gateway.cgi +0 -97
  44. data/doc/README_FOR_APP +0 -2
  45. data/environments/boot.rb +0 -114
  46. data/environments/development.rb +0 -17
  47. data/environments/environment.rb +0 -41
  48. data/environments/production.rb +0 -28
  49. data/environments/test.rb +0 -28
  50. data/fresh_rakefile +0 -10
  51. data/helpers/application_controller.rb +0 -10
  52. data/helpers/application_helper.rb +0 -3
  53. data/helpers/performance_test.rb +0 -9
  54. data/helpers/test_helper.rb +0 -38
  55. data/html/404.html +0 -30
  56. data/html/422.html +0 -30
  57. data/html/500.html +0 -30
  58. data/html/favicon.ico +0 -0
  59. data/html/images/rails.png +0 -0
  60. data/html/index.html +0 -275
  61. data/html/javascripts/application.js +0 -2
  62. data/html/javascripts/controls.js +0 -963
  63. data/html/javascripts/dragdrop.js +0 -973
  64. data/html/javascripts/effects.js +0 -1128
  65. data/html/javascripts/prototype.js +0 -4320
  66. data/html/robots.txt +0 -5
  67. data/lib/code_statistics.rb +0 -107
  68. data/lib/commands/about.rb +0 -3
  69. data/lib/commands/console.rb +0 -45
  70. data/lib/commands/dbconsole.rb +0 -87
  71. data/lib/commands/destroy.rb +0 -6
  72. data/lib/commands/generate.rb +0 -6
  73. data/lib/commands/ncgi/listener +0 -86
  74. data/lib/commands/ncgi/tracker +0 -69
  75. data/lib/commands/performance/benchmarker.rb +0 -24
  76. data/lib/commands/performance/profiler.rb +0 -50
  77. data/lib/commands/plugin.rb +0 -968
  78. data/lib/commands/runner.rb +0 -54
  79. data/lib/commands/server.rb +0 -114
  80. data/lib/commands/update.rb +0 -4
  81. data/lib/commands.rb +0 -17
  82. data/lib/console_app.rb +0 -30
  83. data/lib/console_sandbox.rb +0 -6
  84. data/lib/console_with_helpers.rb +0 -5
  85. data/lib/dispatcher.rb +0 -24
  86. data/lib/fcgi_handler.rb +0 -239
  87. data/lib/initializer.rb +0 -1152
  88. data/lib/performance_test_help.rb +0 -5
  89. data/lib/rails/backtrace_cleaner.rb +0 -54
  90. data/lib/rails/gem_builder.rb +0 -21
  91. data/lib/rails/gem_dependency.rb +0 -317
  92. data/lib/rails/plugin/loader.rb +0 -198
  93. data/lib/rails/plugin/locator.rb +0 -100
  94. data/lib/rails/plugin.rb +0 -179
  95. data/lib/rails/rack/debugger.rb +0 -23
  96. data/lib/rails/rack/log_tailer.rb +0 -35
  97. data/lib/rails/rack/metal.rb +0 -51
  98. data/lib/rails/rack/static.rb +0 -46
  99. data/lib/rails/rack.rb +0 -8
  100. data/lib/rails/vendor_gem_source_index.rb +0 -140
  101. data/lib/rails/version.rb +0 -9
  102. data/lib/rails_generator/base.rb +0 -266
  103. data/lib/rails_generator/commands.rb +0 -621
  104. data/lib/rails_generator/generated_attribute.rb +0 -47
  105. data/lib/rails_generator/generators/applications/app/USAGE +0 -9
  106. data/lib/rails_generator/generators/applications/app/app_generator.rb +0 -266
  107. data/lib/rails_generator/generators/applications/app/scm/git.rb +0 -18
  108. data/lib/rails_generator/generators/applications/app/scm/scm.rb +0 -8
  109. data/lib/rails_generator/generators/applications/app/scm/svn.rb +0 -7
  110. data/lib/rails_generator/generators/applications/app/template_runner.rb +0 -401
  111. data/lib/rails_generator/generators/components/controller/USAGE +0 -30
  112. data/lib/rails_generator/generators/components/controller/controller_generator.rb +0 -43
  113. data/lib/rails_generator/generators/components/controller/templates/controller.rb +0 -7
  114. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +0 -8
  115. data/lib/rails_generator/generators/components/controller/templates/helper.rb +0 -2
  116. data/lib/rails_generator/generators/components/controller/templates/helper_test.rb +0 -4
  117. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +0 -2
  118. data/lib/rails_generator/generators/components/helper/USAGE +0 -24
  119. data/lib/rails_generator/generators/components/helper/helper_generator.rb +0 -25
  120. data/lib/rails_generator/generators/components/helper/templates/helper.rb +0 -2
  121. data/lib/rails_generator/generators/components/helper/templates/helper_test.rb +0 -4
  122. data/lib/rails_generator/generators/components/integration_test/USAGE +0 -8
  123. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +0 -16
  124. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +0 -10
  125. data/lib/rails_generator/generators/components/mailer/USAGE +0 -16
  126. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +0 -30
  127. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +0 -3
  128. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  129. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +0 -15
  130. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +0 -20
  131. data/lib/rails_generator/generators/components/mailer/templates/view.erb +0 -3
  132. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  133. data/lib/rails_generator/generators/components/metal/USAGE +0 -8
  134. data/lib/rails_generator/generators/components/metal/metal_generator.rb +0 -8
  135. data/lib/rails_generator/generators/components/metal/templates/metal.rb +0 -12
  136. data/lib/rails_generator/generators/components/migration/USAGE +0 -29
  137. data/lib/rails_generator/generators/components/migration/migration_generator.rb +0 -20
  138. data/lib/rails_generator/generators/components/migration/templates/migration.rb +0 -11
  139. data/lib/rails_generator/generators/components/model/USAGE +0 -27
  140. data/lib/rails_generator/generators/components/model/model_generator.rb +0 -52
  141. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +0 -23
  142. data/lib/rails_generator/generators/components/model/templates/migration.rb +0 -16
  143. data/lib/rails_generator/generators/components/model/templates/model.rb +0 -5
  144. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +0 -8
  145. data/lib/rails_generator/generators/components/observer/USAGE +0 -13
  146. data/lib/rails_generator/generators/components/observer/observer_generator.rb +0 -16
  147. data/lib/rails_generator/generators/components/observer/templates/observer.rb +0 -2
  148. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -8
  149. data/lib/rails_generator/generators/components/performance_test/USAGE +0 -8
  150. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +0 -16
  151. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +0 -9
  152. data/lib/rails_generator/generators/components/plugin/USAGE +0 -25
  153. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +0 -39
  154. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +0 -20
  155. data/lib/rails_generator/generators/components/plugin/templates/README +0 -13
  156. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -23
  157. data/lib/rails_generator/generators/components/plugin/templates/USAGE +0 -8
  158. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +0 -8
  159. data/lib/rails_generator/generators/components/plugin/templates/init.rb +0 -1
  160. data/lib/rails_generator/generators/components/plugin/templates/install.rb +0 -1
  161. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +0 -1
  162. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +0 -4
  163. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +0 -4
  164. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +0 -1
  165. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +0 -8
  166. data/lib/rails_generator/generators/components/resource/USAGE +0 -23
  167. data/lib/rails_generator/generators/components/resource/resource_generator.rb +0 -76
  168. data/lib/rails_generator/generators/components/resource/templates/controller.rb +0 -2
  169. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +0 -8
  170. data/lib/rails_generator/generators/components/resource/templates/helper.rb +0 -2
  171. data/lib/rails_generator/generators/components/resource/templates/helper_test.rb +0 -4
  172. data/lib/rails_generator/generators/components/scaffold/USAGE +0 -29
  173. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -103
  174. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +0 -83
  175. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +0 -45
  176. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +0 -2
  177. data/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb +0 -4
  178. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +0 -17
  179. data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -54
  180. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +0 -18
  181. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +0 -24
  182. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +0 -17
  183. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +0 -10
  184. data/lib/rails_generator/generators/components/session_migration/USAGE +0 -10
  185. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +0 -18
  186. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +0 -16
  187. data/lib/rails_generator/lookup.rb +0 -249
  188. data/lib/rails_generator/manifest.rb +0 -53
  189. data/lib/rails_generator/options.rb +0 -150
  190. data/lib/rails_generator/scripts/destroy.rb +0 -29
  191. data/lib/rails_generator/scripts/generate.rb +0 -7
  192. data/lib/rails_generator/scripts/update.rb +0 -12
  193. data/lib/rails_generator/scripts.rb +0 -89
  194. data/lib/rails_generator/secret_key_generator.rb +0 -24
  195. data/lib/rails_generator/simple_logger.rb +0 -46
  196. data/lib/rails_generator/spec.rb +0 -44
  197. data/lib/rails_generator.rb +0 -46
  198. data/lib/railties_path.rb +0 -1
  199. data/lib/ruby_version_check.rb +0 -17
  200. data/lib/rubyprof_ext.rb +0 -35
  201. data/lib/source_annotation_extractor.rb +0 -102
  202. data/lib/tasks/annotations.rake +0 -20
  203. data/lib/tasks/databases.rake +0 -436
  204. data/lib/tasks/documentation.rake +0 -93
  205. data/lib/tasks/framework.rake +0 -146
  206. data/lib/tasks/gems.rake +0 -78
  207. data/lib/tasks/log.rake +0 -9
  208. data/lib/tasks/middleware.rake +0 -7
  209. data/lib/tasks/misc.rake +0 -63
  210. data/lib/tasks/rails.rb +0 -14
  211. data/lib/tasks/routes.rake +0 -18
  212. data/lib/tasks/statistics.rake +0 -17
  213. data/lib/tasks/testing.rake +0 -139
  214. data/lib/tasks/tmp.rake +0 -37
  215. data/lib/test_help.rb +0 -38
  216. data/lib/webrick_server.rb +0 -156
  217. data/railties.gemspec +0 -22
@@ -1,54 +0,0 @@
1
- require 'optparse'
2
-
3
- options = { :environment => (ENV['RAILS_ENV'] || "development").dup }
4
- code_or_file = nil
5
-
6
- ARGV.clone.options do |opts|
7
- script_name = File.basename($0)
8
- opts.banner = "Usage: #{$0} [options] ('Some.ruby(code)' or a filename)"
9
-
10
- opts.separator ""
11
-
12
- opts.on("-e", "--environment=name", String,
13
- "Specifies the environment for the runner to operate under (test/development/production).",
14
- "Default: development") { |v| options[:environment] = v }
15
-
16
- opts.separator ""
17
-
18
- opts.on("-h", "--help",
19
- "Show this help message.") { $stderr.puts opts; exit }
20
-
21
- if RUBY_PLATFORM !~ /(:?mswin|mingw)/
22
- opts.separator ""
23
- opts.separator "You can also use runner as a shebang line for your scripts like this:"
24
- opts.separator "-------------------------------------------------------------"
25
- opts.separator "#!/usr/bin/env #{File.expand_path($0)}"
26
- opts.separator ""
27
- opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
28
- opts.separator "-------------------------------------------------------------"
29
- end
30
-
31
- opts.order! { |o| code_or_file ||= o } rescue retry
32
- end
33
-
34
- ARGV.delete(code_or_file)
35
-
36
- ENV["RAILS_ENV"] = options[:environment]
37
- RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
38
-
39
- require RAILS_ROOT + '/config/environment'
40
-
41
- begin
42
- if code_or_file.nil?
43
- $stderr.puts "Run '#{$0} -h' for help."
44
- exit 1
45
- elsif File.exist?(code_or_file)
46
- eval(File.read(code_or_file), nil, code_or_file)
47
- else
48
- eval(code_or_file)
49
- end
50
- ensure
51
- if defined? Rails
52
- Rails.logger.flush if Rails.logger.respond_to?(:flush)
53
- end
54
- end
@@ -1,114 +0,0 @@
1
- require 'active_support'
2
- require 'action_controller'
3
-
4
- require 'fileutils'
5
- require 'optparse'
6
-
7
- # TODO: Push Thin adapter upstream so we don't need worry about requiring it
8
- begin
9
- require_library_or_gem 'thin'
10
- rescue Exception
11
- # Thin not available
12
- end
13
-
14
- options = {
15
- :Port => 3000,
16
- :Host => "0.0.0.0",
17
- :environment => (ENV['RAILS_ENV'] || "development").dup,
18
- :config => RAILS_ROOT + "/config.ru",
19
- :detach => false,
20
- :debugger => false,
21
- :path => nil
22
- }
23
-
24
- ARGV.clone.options do |opts|
25
- opts.on("-p", "--port=port", Integer,
26
- "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
27
- opts.on("-b", "--binding=ip", String,
28
- "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
29
- opts.on("-c", "--config=file", String,
30
- "Use custom rackup configuration file") { |v| options[:config] = v }
31
- opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true }
32
- opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true }
33
- opts.on("-e", "--environment=name", String,
34
- "Specifies the environment to run this server under (test/development/production).",
35
- "Default: development") { |v| options[:environment] = v }
36
- opts.on("-P", "--path=/path", String, "Runs Rails app mounted at a specific path.", "Default: /") { |v| options[:path] = v }
37
-
38
- opts.separator ""
39
-
40
- opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
41
-
42
- opts.parse!
43
- end
44
-
45
- server = Rack::Handler.get(ARGV.first) rescue nil
46
- unless server
47
- begin
48
- server = Rack::Handler::Mongrel
49
- rescue LoadError => e
50
- server = Rack::Handler::WEBrick
51
- end
52
- end
53
-
54
- puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
55
- puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}#{options[:path]}"
56
-
57
- %w(cache pids sessions sockets).each do |dir_to_make|
58
- FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make))
59
- end
60
-
61
- if options[:detach]
62
- Process.daemon
63
- pid = "#{RAILS_ROOT}/tmp/pids/server.pid"
64
- File.open(pid, 'w'){ |f| f.write(Process.pid) }
65
- at_exit { File.delete(pid) if File.exist?(pid) }
66
- end
67
-
68
- ENV["RAILS_ENV"] = options[:environment]
69
- RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
70
-
71
- if File.exist?(options[:config])
72
- config = options[:config]
73
- if config =~ /\.ru$/
74
- cfgfile = File.read(config)
75
- if cfgfile[/^#\\(.*)/]
76
- opts.parse!($1.split(/\s+/))
77
- end
78
- inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config)
79
- else
80
- require config
81
- inner_app = Object.const_get(File.basename(config, '.rb').capitalize)
82
- end
83
- else
84
- require RAILS_ROOT + "/config/environment"
85
- inner_app = ActionController::Dispatcher.new
86
- end
87
-
88
- if options[:path].nil?
89
- map_path = "/"
90
- else
91
- ActionController::Base.relative_url_root = options[:path]
92
- map_path = options[:path]
93
- end
94
-
95
- app = Rack::Builder.new {
96
- use Rails::Rack::LogTailer unless options[:detach]
97
- use Rails::Rack::Debugger if options[:debugger]
98
- map map_path do
99
- use Rails::Rack::Static
100
- run inner_app
101
- end
102
- }.to_app
103
-
104
- puts "=> Call with -d to detach"
105
-
106
- trap(:INT) { exit }
107
-
108
- puts "=> Ctrl-C to shutdown server"
109
-
110
- begin
111
- server.run(app, options.merge(:AccessLog => []))
112
- ensure
113
- puts 'Exiting'
114
- end
@@ -1,4 +0,0 @@
1
- require "#{RAILS_ROOT}/config/environment"
2
- require 'rails_generator'
3
- require 'rails_generator/scripts/update'
4
- Rails::Generator::Scripts::Update.new.run(ARGV)
data/lib/commands.rb DELETED
@@ -1,17 +0,0 @@
1
- commands = Dir["#{File.dirname(__FILE__)}/commands/*.rb"].collect { |file_path| File.basename(file_path).split(".").first }
2
-
3
- if commands.include?(ARGV.first)
4
- require "#{File.dirname(__FILE__)}/commands/#{ARGV.shift}"
5
- else
6
- puts <<-USAGE
7
- The 'run' provides a unified access point for all the default Rails' commands.
8
-
9
- Usage: ./script/run <command> [OPTIONS]
10
-
11
- Examples:
12
- ./script/run generate controller Admin
13
- ./script/run process reaper
14
-
15
- USAGE
16
- puts "Choose: #{commands.join(", ")}"
17
- end
data/lib/console_app.rb DELETED
@@ -1,30 +0,0 @@
1
- require 'active_support/test_case'
2
- require 'action_controller'
3
-
4
- # work around the at_exit hook in test/unit, which kills IRB
5
- Test::Unit.run = true if Test::Unit.respond_to?(:run=)
6
-
7
- # reference the global "app" instance, created on demand. To recreate the
8
- # instance, pass a non-false value as the parameter.
9
- def app(create=false)
10
- @app_integration_instance = nil if create
11
- @app_integration_instance ||= new_session do |sess|
12
- sess.host! "www.example.com"
13
- end
14
- end
15
-
16
- # create a new session. If a block is given, the new session will be yielded
17
- # to the block before being returned.
18
- def new_session
19
- session = ActionController::Integration::Session.new
20
- yield session if block_given?
21
- session
22
- end
23
-
24
- #reloads the environment
25
- def reload!
26
- puts "Reloading..."
27
- Dispatcher.cleanup_application
28
- Dispatcher.reload_application
29
- true
30
- end
@@ -1,6 +0,0 @@
1
- ActiveRecord::Base.connection.increment_open_transactions
2
- ActiveRecord::Base.connection.begin_db_transaction
3
- at_exit do
4
- ActiveRecord::Base.connection.rollback_db_transaction
5
- ActiveRecord::Base.connection.decrement_open_transactions
6
- end
@@ -1,5 +0,0 @@
1
- def helper
2
- @helper ||= ApplicationController.helpers
3
- end
4
-
5
- @controller = ApplicationController.new
data/lib/dispatcher.rb DELETED
@@ -1,24 +0,0 @@
1
- #--
2
- # Copyright (c) 2004-2010 David Heinemeier Hansson
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
- require 'action_controller/dispatcher'
24
- Dispatcher = ActionController::Dispatcher
data/lib/fcgi_handler.rb DELETED
@@ -1,239 +0,0 @@
1
- require 'fcgi'
2
- require 'logger'
3
- require 'dispatcher'
4
- require 'rbconfig'
5
-
6
- class RailsFCGIHandler
7
- SIGNALS = {
8
- 'HUP' => :reload,
9
- 'INT' => :exit_now,
10
- 'TERM' => :exit_now,
11
- 'USR1' => :exit,
12
- 'USR2' => :restart
13
- }
14
- GLOBAL_SIGNALS = SIGNALS.keys - %w(USR1)
15
-
16
- attr_reader :when_ready
17
-
18
- attr_accessor :log_file_path
19
- attr_accessor :gc_request_period
20
-
21
- # Initialize and run the FastCGI instance, passing arguments through to new.
22
- def self.process!(*args, &block)
23
- new(*args, &block).process!
24
- end
25
-
26
- # Initialize the FastCGI instance with the path to a crash log
27
- # detailing unhandled exceptions (default RAILS_ROOT/log/fastcgi.crash.log)
28
- # and the number of requests to process between garbage collection runs
29
- # (default nil for normal GC behavior.) Optionally, pass a block which
30
- # takes this instance as an argument for further configuration.
31
- def initialize(log_file_path = nil, gc_request_period = nil)
32
- self.log_file_path = log_file_path || "#{RAILS_ROOT}/log/fastcgi.crash.log"
33
- self.gc_request_period = gc_request_period
34
-
35
- # Yield for additional configuration.
36
- yield self if block_given?
37
-
38
- # Safely install signal handlers.
39
- install_signal_handlers
40
-
41
- @app = Dispatcher.new
42
-
43
- # Start error timestamp at 11 seconds ago.
44
- @last_error_on = Time.now - 11
45
- end
46
-
47
- def process!(provider = FCGI)
48
- mark_features!
49
-
50
- dispatcher_log :info, 'starting'
51
- process_each_request provider
52
- dispatcher_log :info, 'stopping gracefully'
53
-
54
- rescue Exception => error
55
- case error
56
- when SystemExit
57
- dispatcher_log :info, 'stopping after explicit exit'
58
- when SignalException
59
- dispatcher_error error, 'stopping after unhandled signal'
60
- else
61
- # Retry if exceptions occur more than 10 seconds apart.
62
- if Time.now - @last_error_on > 10
63
- @last_error_on = Time.now
64
- dispatcher_error error, 'retrying after unhandled exception'
65
- retry
66
- else
67
- dispatcher_error error, 'stopping after unhandled exception within 10 seconds of the last'
68
- end
69
- end
70
- end
71
-
72
- protected
73
- def process_each_request(provider)
74
- request = nil
75
-
76
- catch :exit do
77
- provider.each do |request|
78
- process_request(request)
79
-
80
- case when_ready
81
- when :reload
82
- reload!
83
- when :restart
84
- close_connection(request)
85
- restart!
86
- when :exit
87
- close_connection(request)
88
- throw :exit
89
- end
90
- end
91
- end
92
- rescue SignalException => signal
93
- raise unless signal.message == 'SIGUSR1'
94
- close_connection(request)
95
- end
96
-
97
- def process_request(request)
98
- @processing, @when_ready = true, nil
99
- gc_countdown
100
-
101
- with_signal_handler 'USR1' do
102
- begin
103
- ::Rack::Handler::FastCGI.serve(request, @app)
104
- rescue SignalException, SystemExit
105
- raise
106
- rescue Exception => error
107
- dispatcher_error error, 'unhandled dispatch error'
108
- end
109
- end
110
- ensure
111
- @processing = false
112
- end
113
-
114
- def logger
115
- @logger ||= Logger.new(@log_file_path)
116
- end
117
-
118
- def dispatcher_log(level, msg)
119
- time_str = Time.now.strftime("%d/%b/%Y:%H:%M:%S")
120
- logger.send(level, "[#{time_str} :: #{$$}] #{msg}")
121
- rescue Exception => log_error # Logger errors
122
- STDERR << "Couldn't write to #{@log_file_path.inspect}: #{msg}\n"
123
- STDERR << " #{log_error.class}: #{log_error.message}\n"
124
- end
125
-
126
- def dispatcher_error(e, msg = "")
127
- error_message =
128
- "Dispatcher failed to catch: #{e} (#{e.class})\n" +
129
- " #{e.backtrace.join("\n ")}\n#{msg}"
130
- dispatcher_log(:error, error_message)
131
- end
132
-
133
- def install_signal_handlers
134
- GLOBAL_SIGNALS.each { |signal| install_signal_handler(signal) }
135
- end
136
-
137
- def install_signal_handler(signal, handler = nil)
138
- if SIGNALS.include?(signal) && self.class.method_defined?(name = "#{SIGNALS[signal]}_handler")
139
- handler ||= method(name).to_proc
140
-
141
- begin
142
- trap(signal, handler)
143
- rescue ArgumentError
144
- dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
145
- end
146
- else
147
- dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
148
- end
149
- end
150
-
151
- def with_signal_handler(signal)
152
- install_signal_handler(signal)
153
- yield
154
- ensure
155
- install_signal_handler(signal, 'DEFAULT')
156
- end
157
-
158
- def exit_now_handler(signal)
159
- dispatcher_log :info, "asked to stop immediately"
160
- exit
161
- end
162
-
163
- def exit_handler(signal)
164
- dispatcher_log :info, "asked to stop ASAP"
165
- if @processing
166
- @when_ready = :exit
167
- else
168
- throw :exit
169
- end
170
- end
171
-
172
- def reload_handler(signal)
173
- dispatcher_log :info, "asked to reload ASAP"
174
- if @processing
175
- @when_ready = :reload
176
- else
177
- reload!
178
- end
179
- end
180
-
181
- def restart_handler(signal)
182
- dispatcher_log :info, "asked to restart ASAP"
183
- if @processing
184
- @when_ready = :restart
185
- else
186
- restart!
187
- end
188
- end
189
-
190
- def restart!
191
- config = ::Config::CONFIG
192
- ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
193
- command_line = [ruby, $0, ARGV].flatten.join(' ')
194
-
195
- dispatcher_log :info, "restarted"
196
-
197
- # close resources as they won't be closed by
198
- # the OS when using exec
199
- logger.close rescue nil
200
- Rails.logger.close rescue nil
201
-
202
- exec(command_line)
203
- end
204
-
205
- def reload!
206
- run_gc! if gc_request_period
207
- restore!
208
- @when_ready = nil
209
- dispatcher_log :info, "reloaded"
210
- end
211
-
212
- # Make a note of $" so we can safely reload this instance.
213
- def mark_features!
214
- @features = $".clone
215
- end
216
-
217
- def restore!
218
- $".replace @features
219
- Dispatcher.reset_application!
220
- ActionController::Routing::Routes.reload
221
- end
222
-
223
- def run_gc!
224
- @gc_request_countdown = gc_request_period
225
- GC.enable; GC.start; GC.disable
226
- end
227
-
228
- def gc_countdown
229
- if gc_request_period
230
- @gc_request_countdown ||= gc_request_period
231
- @gc_request_countdown -= 1
232
- run_gc! if @gc_request_countdown <= 0
233
- end
234
- end
235
-
236
- def close_connection(request)
237
- request.finish if request
238
- end
239
- end