rails 2.2.3 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (229) hide show
  1. data/CHANGELOG +272 -191
  2. data/MIT-LICENSE +1 -1
  3. data/README +6 -19
  4. data/Rakefile +24 -71
  5. data/bin/rails +1 -0
  6. data/builtin/rails_info/rails/info.rb +12 -8
  7. data/configs/databases/mysql.yml +3 -0
  8. data/configs/initializers/backtrace_silencers.rb +7 -0
  9. data/configs/initializers/new_rails_defaults.rb +2 -0
  10. data/configs/initializers/session_store.rb +15 -0
  11. data/dispatches/config.ru +7 -0
  12. data/doc/README_FOR_APP +2 -5
  13. data/environments/boot.rb +1 -0
  14. data/environments/environment.rb +14 -48
  15. data/environments/production.rb +11 -7
  16. data/environments/test.rb +6 -0
  17. data/helpers/application_controller.rb +10 -0
  18. data/helpers/test_helper.rb +1 -1
  19. data/html/500.html +0 -3
  20. data/html/index.html +1 -0
  21. data/lib/commands/about.rb +1 -1
  22. data/lib/commands/dbconsole.rb +18 -2
  23. data/lib/commands/plugin.rb +4 -3
  24. data/lib/commands/runner.rb +13 -7
  25. data/lib/commands/server.rb +98 -33
  26. data/lib/console_app.rb +4 -4
  27. data/lib/console_with_helpers.rb +2 -23
  28. data/lib/dispatcher.rb +1 -1
  29. data/lib/fcgi_handler.rb +12 -10
  30. data/lib/initializer.rb +108 -41
  31. data/lib/rails/backtrace_cleaner.rb +54 -0
  32. data/lib/rails/gem_dependency.rb +124 -94
  33. data/lib/rails/plugin.rb +49 -6
  34. data/lib/rails/plugin/loader.rb +66 -27
  35. data/lib/rails/plugin/locator.rb +1 -1
  36. data/lib/rails/rack.rb +3 -1
  37. data/lib/rails/rack/debugger.rb +21 -0
  38. data/lib/rails/rack/log_tailer.rb +35 -0
  39. data/lib/rails/rack/metal.rb +51 -0
  40. data/lib/rails/rack/static.rb +15 -4
  41. data/lib/rails/version.rb +2 -2
  42. data/lib/rails_generator/base.rb +3 -0
  43. data/lib/rails_generator/commands.rb +8 -3
  44. data/lib/rails_generator/generators/applications/app/app_generator.rb +210 -136
  45. data/lib/rails_generator/generators/applications/app/scm/git.rb +16 -0
  46. data/lib/rails_generator/generators/applications/app/scm/scm.rb +8 -0
  47. data/lib/rails_generator/generators/applications/app/scm/svn.rb +7 -0
  48. data/lib/rails_generator/generators/applications/app/template_runner.rb +401 -0
  49. data/lib/rails_generator/generators/components/controller/USAGE +12 -11
  50. data/lib/rails_generator/generators/components/controller/controller_generator.rb +7 -1
  51. data/lib/rails_generator/generators/components/controller/templates/helper_test.rb +4 -0
  52. data/lib/rails_generator/generators/components/helper/USAGE +24 -0
  53. data/lib/rails_generator/generators/components/helper/helper_generator.rb +25 -0
  54. data/lib/rails_generator/generators/components/helper/templates/helper.rb +2 -0
  55. data/lib/rails_generator/generators/components/helper/templates/helper_test.rb +4 -0
  56. data/lib/rails_generator/generators/components/metal/USAGE +8 -0
  57. data/lib/rails_generator/generators/components/metal/metal_generator.rb +8 -0
  58. data/lib/rails_generator/generators/components/metal/templates/metal.rb +12 -0
  59. data/lib/rails_generator/generators/components/resource/USAGE +2 -2
  60. data/lib/rails_generator/generators/components/resource/resource_generator.rb +2 -0
  61. data/lib/rails_generator/generators/components/resource/templates/helper_test.rb +4 -0
  62. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +2 -0
  63. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +1 -1
  64. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +4 -4
  65. data/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb +4 -0
  66. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +1 -1
  67. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +2 -2
  68. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +2 -2
  69. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +2 -2
  70. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +1 -1
  71. data/lib/rails_generator/secret_key_generator.rb +2 -0
  72. data/lib/tasks/databases.rake +13 -6
  73. data/lib/tasks/documentation.rake +2 -9
  74. data/lib/tasks/framework.rake +26 -1
  75. data/lib/tasks/gems.rake +33 -48
  76. data/lib/tasks/middleware.rake +7 -0
  77. data/lib/tasks/misc.rake +7 -0
  78. data/lib/tasks/statistics.rake +0 -1
  79. data/lib/tasks/testing.rake +5 -5
  80. data/lib/tasks/tmp.rake +2 -2
  81. data/lib/test_help.rb +16 -8
  82. metadata +92 -159
  83. data/bin/performance/request +0 -3
  84. data/bin/process/inspector +0 -3
  85. data/bin/process/reaper +0 -3
  86. data/bin/process/spawner +0 -3
  87. data/config.ru +0 -17
  88. data/configs/apache.conf +0 -40
  89. data/configs/lighttpd.conf +0 -54
  90. data/doc/guides/html/2_2_release_notes.html +0 -1185
  91. data/doc/guides/html/actioncontroller_basics.html +0 -1270
  92. data/doc/guides/html/activerecord_validations_callbacks.html +0 -749
  93. data/doc/guides/html/association_basics.html +0 -2585
  94. data/doc/guides/html/authors.html +0 -240
  95. data/doc/guides/html/benchmarking_and_profiling.html +0 -1018
  96. data/doc/guides/html/caching_with_rails.html +0 -583
  97. data/doc/guides/html/command_line.html +0 -434
  98. data/doc/guides/html/configuring.html +0 -438
  99. data/doc/guides/html/creating_plugins.html +0 -1594
  100. data/doc/guides/html/debugging_rails_applications.html +0 -1175
  101. data/doc/guides/html/finders.html +0 -1090
  102. data/doc/guides/html/form_helpers.html +0 -638
  103. data/doc/guides/html/getting_started_with_rails.html +0 -2066
  104. data/doc/guides/html/index.html +0 -349
  105. data/doc/guides/html/layouts_and_rendering.html +0 -1406
  106. data/doc/guides/html/migrations.html +0 -921
  107. data/doc/guides/html/routing_outside_in.html +0 -2213
  108. data/doc/guides/html/security.html +0 -1346
  109. data/doc/guides/html/testing_rails_applications.html +0 -1859
  110. data/doc/guides/source/2_2_release_notes.txt +0 -435
  111. data/doc/guides/source/actioncontroller_basics/changelog.txt +0 -5
  112. data/doc/guides/source/actioncontroller_basics/cookies.txt +0 -34
  113. data/doc/guides/source/actioncontroller_basics/csrf.txt +0 -32
  114. data/doc/guides/source/actioncontroller_basics/filters.txt +0 -119
  115. data/doc/guides/source/actioncontroller_basics/http_auth.txt +0 -24
  116. data/doc/guides/source/actioncontroller_basics/index.txt +0 -40
  117. data/doc/guides/source/actioncontroller_basics/introduction.txt +0 -9
  118. data/doc/guides/source/actioncontroller_basics/methods.txt +0 -39
  119. data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +0 -14
  120. data/doc/guides/source/actioncontroller_basics/params.txt +0 -93
  121. data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +0 -43
  122. data/doc/guides/source/actioncontroller_basics/rescue.txt +0 -67
  123. data/doc/guides/source/actioncontroller_basics/session.txt +0 -187
  124. data/doc/guides/source/actioncontroller_basics/streaming.txt +0 -91
  125. data/doc/guides/source/actioncontroller_basics/verification.txt +0 -40
  126. data/doc/guides/source/active_record_basics.txt +0 -181
  127. data/doc/guides/source/activerecord_validations_callbacks.txt +0 -404
  128. data/doc/guides/source/association_basics.txt +0 -1840
  129. data/doc/guides/source/authors.txt +0 -39
  130. data/doc/guides/source/benchmarking_and_profiling/appendix.txt +0 -95
  131. data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +0 -105
  132. data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +0 -185
  133. data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +0 -27
  134. data/doc/guides/source/benchmarking_and_profiling/index.txt +0 -242
  135. data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +0 -179
  136. data/doc/guides/source/benchmarking_and_profiling/statistics.txt +0 -57
  137. data/doc/guides/source/caching_with_rails.txt +0 -367
  138. data/doc/guides/source/command_line.txt +0 -147
  139. data/doc/guides/source/configuring.txt +0 -225
  140. data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +0 -191
  141. data/doc/guides/source/creating_plugins/appendix.txt +0 -46
  142. data/doc/guides/source/creating_plugins/controllers.txt +0 -59
  143. data/doc/guides/source/creating_plugins/core_ext.txt +0 -123
  144. data/doc/guides/source/creating_plugins/custom_route.txt +0 -69
  145. data/doc/guides/source/creating_plugins/gem.txt +0 -1
  146. data/doc/guides/source/creating_plugins/generator_method.txt +0 -89
  147. data/doc/guides/source/creating_plugins/helpers.txt +0 -51
  148. data/doc/guides/source/creating_plugins/index.txt +0 -52
  149. data/doc/guides/source/creating_plugins/migration_generator.txt +0 -156
  150. data/doc/guides/source/creating_plugins/models.txt +0 -76
  151. data/doc/guides/source/creating_plugins/odds_and_ends.txt +0 -69
  152. data/doc/guides/source/creating_plugins/test_setup.txt +0 -230
  153. data/doc/guides/source/debugging_rails_applications.txt +0 -733
  154. data/doc/guides/source/finders.txt +0 -668
  155. data/doc/guides/source/form_helpers.txt +0 -345
  156. data/doc/guides/source/getting_started_with_rails.txt +0 -1256
  157. data/doc/guides/source/images/belongs_to.png +0 -0
  158. data/doc/guides/source/images/bullet.gif +0 -0
  159. data/doc/guides/source/images/csrf.png +0 -0
  160. data/doc/guides/source/images/habtm.png +0 -0
  161. data/doc/guides/source/images/has_many.png +0 -0
  162. data/doc/guides/source/images/has_many_through.png +0 -0
  163. data/doc/guides/source/images/has_one.png +0 -0
  164. data/doc/guides/source/images/has_one_through.png +0 -0
  165. data/doc/guides/source/images/header_backdrop.png +0 -0
  166. data/doc/guides/source/images/icons/README +0 -5
  167. data/doc/guides/source/images/icons/callouts/1.png +0 -0
  168. data/doc/guides/source/images/icons/callouts/10.png +0 -0
  169. data/doc/guides/source/images/icons/callouts/11.png +0 -0
  170. data/doc/guides/source/images/icons/callouts/12.png +0 -0
  171. data/doc/guides/source/images/icons/callouts/13.png +0 -0
  172. data/doc/guides/source/images/icons/callouts/14.png +0 -0
  173. data/doc/guides/source/images/icons/callouts/15.png +0 -0
  174. data/doc/guides/source/images/icons/callouts/2.png +0 -0
  175. data/doc/guides/source/images/icons/callouts/3.png +0 -0
  176. data/doc/guides/source/images/icons/callouts/4.png +0 -0
  177. data/doc/guides/source/images/icons/callouts/5.png +0 -0
  178. data/doc/guides/source/images/icons/callouts/6.png +0 -0
  179. data/doc/guides/source/images/icons/callouts/7.png +0 -0
  180. data/doc/guides/source/images/icons/callouts/8.png +0 -0
  181. data/doc/guides/source/images/icons/callouts/9.png +0 -0
  182. data/doc/guides/source/images/icons/caution.png +0 -0
  183. data/doc/guides/source/images/icons/example.png +0 -0
  184. data/doc/guides/source/images/icons/home.png +0 -0
  185. data/doc/guides/source/images/icons/important.png +0 -0
  186. data/doc/guides/source/images/icons/next.png +0 -0
  187. data/doc/guides/source/images/icons/note.png +0 -0
  188. data/doc/guides/source/images/icons/prev.png +0 -0
  189. data/doc/guides/source/images/icons/tip.png +0 -0
  190. data/doc/guides/source/images/icons/up.png +0 -0
  191. data/doc/guides/source/images/icons/warning.png +0 -0
  192. data/doc/guides/source/images/polymorphic.png +0 -0
  193. data/doc/guides/source/images/rails_logo_remix.gif +0 -0
  194. data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
  195. data/doc/guides/source/images/session_fixation.png +0 -0
  196. data/doc/guides/source/index.txt +0 -118
  197. data/doc/guides/source/layouts_and_rendering.txt +0 -982
  198. data/doc/guides/source/migrations/anatomy_of_a_migration.txt +0 -85
  199. data/doc/guides/source/migrations/changelog.txt +0 -5
  200. data/doc/guides/source/migrations/creating_a_migration.txt +0 -109
  201. data/doc/guides/source/migrations/foreign_keys.txt +0 -8
  202. data/doc/guides/source/migrations/index.txt +0 -22
  203. data/doc/guides/source/migrations/rakeing_around.txt +0 -111
  204. data/doc/guides/source/migrations/scheming.txt +0 -47
  205. data/doc/guides/source/migrations/using_models_in_migrations.txt +0 -46
  206. data/doc/guides/source/migrations/writing_a_migration.txt +0 -159
  207. data/doc/guides/source/routing_outside_in.txt +0 -986
  208. data/doc/guides/source/security.txt +0 -984
  209. data/doc/guides/source/stylesheets/base.css +0 -358
  210. data/doc/guides/source/stylesheets/forms.css +0 -35
  211. data/doc/guides/source/stylesheets/more.css +0 -82
  212. data/doc/guides/source/templates/guides.html.erb +0 -97
  213. data/doc/guides/source/templates/inline.css +0 -165
  214. data/doc/guides/source/testing_rails_applications.txt +0 -995
  215. data/helpers/application.rb +0 -15
  216. data/lib/commands/performance/request.rb +0 -6
  217. data/lib/commands/process/inspector.rb +0 -68
  218. data/lib/commands/process/reaper.rb +0 -149
  219. data/lib/commands/process/spawner.rb +0 -219
  220. data/lib/commands/process/spinner.rb +0 -57
  221. data/lib/commands/servers/base.rb +0 -31
  222. data/lib/commands/servers/lighttpd.rb +0 -94
  223. data/lib/commands/servers/mongrel.rb +0 -69
  224. data/lib/commands/servers/new_mongrel.rb +0 -16
  225. data/lib/commands/servers/thin.rb +0 -25
  226. data/lib/commands/servers/webrick.rb +0 -66
  227. data/lib/rails/mongrel_server/commands.rb +0 -342
  228. data/lib/rails/mongrel_server/handler.rb +0 -55
  229. data/lib/rails/rack/logger.rb +0 -28
@@ -1,57 +0,0 @@
1
- require 'optparse'
2
-
3
- def daemonize #:nodoc:
4
- exit if fork # Parent exits, child continues.
5
- Process.setsid # Become session leader.
6
- exit if fork # Zap session leader. See [1].
7
- Dir.chdir "/" # Release old working directory.
8
- File.umask 0000 # Ensure sensible umask. Adjust as needed.
9
- STDIN.reopen "/dev/null" # Free file descriptors and
10
- STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
11
- STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile.
12
- end
13
-
14
- OPTIONS = {
15
- :interval => 5.0,
16
- :command => File.expand_path(RAILS_ROOT + '/script/process/spawner'),
17
- :daemon => false
18
- }
19
-
20
- ARGV.options do |opts|
21
- opts.banner = "Usage: spinner [options]"
22
-
23
- opts.separator ""
24
-
25
- opts.on <<-EOF
26
- Description:
27
- The spinner is a protection loop for the spawner, which will attempt to restart any FCGI processes
28
- that might have been exited or outright crashed. It's a brute-force attempt that'll just try
29
- to run the spawner every X number of seconds, so it does pose a light load on the server.
30
-
31
- Examples:
32
- spinner # attempts to run the spawner with default settings every second with output on the terminal
33
- spinner -i 3 -d # only run the spawner every 3 seconds and detach from the terminal to become a daemon
34
- spinner -c '/path/to/app/script/process/spawner -p 9000 -i 10' -d # using custom spawner
35
- EOF
36
-
37
- opts.on(" Options:")
38
-
39
- opts.on("-c", "--command=path", String) { |v| OPTIONS[:command] = v }
40
- opts.on("-i", "--interval=seconds", Float) { |v| OPTIONS[:interval] = v }
41
- opts.on("-d", "--daemon") { |v| OPTIONS[:daemon] = v }
42
-
43
- opts.separator ""
44
-
45
- opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
46
-
47
- opts.parse!
48
- end
49
-
50
- daemonize if OPTIONS[:daemon]
51
-
52
- trap(OPTIONS[:daemon] ? "TERM" : "INT") { exit }
53
-
54
- loop do
55
- system(OPTIONS[:command])
56
- sleep(OPTIONS[:interval])
57
- end
@@ -1,31 +0,0 @@
1
- def tail(log_file)
2
- cursor = File.size(log_file)
3
- last_checked = Time.now
4
- tail_thread = Thread.new do
5
- File.open(log_file, 'r') do |f|
6
- loop do
7
- f.seek cursor
8
- if f.mtime > last_checked
9
- last_checked = f.mtime
10
- contents = f.read
11
- cursor += contents.length
12
- print contents
13
- end
14
- sleep 1
15
- end
16
- end
17
- end
18
- tail_thread
19
- end
20
-
21
- def start_debugger
22
- begin
23
- require_library_or_gem 'ruby-debug'
24
- Debugger.start
25
- Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
26
- puts "=> Debugger enabled"
27
- rescue Exception
28
- puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
29
- exit
30
- end
31
- end
@@ -1,94 +0,0 @@
1
- require 'rbconfig'
2
- require 'commands/servers/base'
3
-
4
- unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank?
5
- puts "PROBLEM: Lighttpd is not available on your system (or not in your path)"
6
- exit 1
7
- end
8
-
9
- unless defined?(FCGI)
10
- puts "PROBLEM: Lighttpd requires that the FCGI Ruby bindings are installed on the system"
11
- exit 1
12
- end
13
-
14
- require 'initializer'
15
- configuration = Rails::Initializer.run(:initialize_logger).configuration
16
- default_config_file = config_file = Pathname.new("#{RAILS_ROOT}/config/lighttpd.conf").cleanpath
17
-
18
- require 'optparse'
19
-
20
- detach = false
21
- command_line_port = nil
22
-
23
- ARGV.options do |opt|
24
- opt.on("-p", "--port=port", "Changes the server.port number in the config/lighttpd.conf") { |port| command_line_port = port }
25
- opt.on('-c', "--config=#{config_file}", 'Specify a different lighttpd config file.') { |path| config_file = path }
26
- opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 }
27
- opt.on('-d', '-d', 'Call with -d to detach') { detach = true; puts "=> Configuration in config/lighttpd.conf" }
28
- opt.parse!
29
- end
30
-
31
- unless File.exist?(config_file)
32
- if config_file != default_config_file
33
- puts "=> #{config_file} not found."
34
- exit 1
35
- end
36
-
37
- require 'fileutils'
38
-
39
- source = File.expand_path(File.join(File.dirname(__FILE__),
40
- "..", "..", "..", "configs", "lighttpd.conf"))
41
- puts "=> #{config_file} not found, copying from #{source}"
42
-
43
- FileUtils.cp(source, config_file)
44
- end
45
-
46
- # open the config/lighttpd.conf file and add the current user defined port setting to it
47
- if command_line_port
48
- File.open(config_file, 'r+') do |config|
49
- lines = config.readlines
50
-
51
- lines.each do |line|
52
- line.gsub!(/^\s*server.port\s*=\s*(\d+)/, "server.port = #{command_line_port}")
53
- end
54
-
55
- config.rewind
56
- config.print(lines)
57
- config.truncate(config.pos)
58
- end
59
- end
60
-
61
- config = IO.read(config_file)
62
- default_port, default_ip = 3000, '0.0.0.0'
63
- port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port
64
- ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip
65
- puts "=> Rails #{Rails.version} application starting on http://#{ip || default_ip}:#{port || default_port}"
66
-
67
- tail_thread = nil
68
-
69
- if !detach
70
- puts "=> Call with -d to detach"
71
- puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
72
- detach = false
73
- tail_thread = tail(configuration.log_path)
74
- end
75
-
76
- trap(:INT) { exit }
77
-
78
- begin
79
- `rake tmp:sockets:clear` # Needed if lighttpd crashes or otherwise leaves FCGI sockets around
80
- `lighttpd #{!detach ? "-D " : ""}-f #{config_file}`
81
- ensure
82
- unless detach
83
- tail_thread.kill if tail_thread
84
- puts 'Exiting'
85
-
86
- # Ensure FCGI processes are reaped
87
- silence_stream(STDOUT) do
88
- ARGV.replace ['-a', 'kill']
89
- require 'commands/process/reaper'
90
- end
91
-
92
- `rake tmp:sockets:clear` # Remove sockets on clean shutdown
93
- end
94
- end
@@ -1,69 +0,0 @@
1
- require 'rbconfig'
2
- require 'commands/servers/base'
3
-
4
- unless defined?(Mongrel)
5
- puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
6
- exit 1
7
- end
8
-
9
- require 'optparse'
10
-
11
- OPTIONS = {
12
- :port => 3000,
13
- :ip => "0.0.0.0",
14
- :environment => (ENV['RAILS_ENV'] || "development").dup,
15
- :detach => false,
16
- :debugger => false
17
- }
18
-
19
- ARGV.clone.options do |opts|
20
- opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v }
21
- opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
22
- opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true }
23
- opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true }
24
- opts.on("-e", "--environment=name", String,
25
- "Specifies the environment to run this server under (test/development/production).",
26
- "Default: development") { |v| OPTIONS[:environment] = v }
27
-
28
- opts.separator ""
29
-
30
- opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
31
-
32
- opts.parse!
33
- end
34
-
35
- puts "=> Rails #{Rails.version} application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
36
-
37
- parameters = [
38
- "start",
39
- "-p", OPTIONS[:port].to_s,
40
- "-a", OPTIONS[:ip].to_s,
41
- "-e", OPTIONS[:environment],
42
- "-P", "#{RAILS_ROOT}/tmp/pids/mongrel.pid"
43
- ]
44
-
45
- if OPTIONS[:detach]
46
- `mongrel_rails #{parameters.join(" ")} -d`
47
- else
48
- ENV["RAILS_ENV"] = OPTIONS[:environment]
49
- RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
50
-
51
- start_debugger if OPTIONS[:debugger]
52
-
53
- puts "=> Call with -d to detach"
54
- puts "=> Ctrl-C to shutdown server"
55
-
56
- log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath
57
- open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log
58
- tail_thread = tail(log)
59
-
60
- trap(:INT) { exit }
61
-
62
- begin
63
- silence_warnings { ARGV = parameters }
64
- load("mongrel_rails")
65
- ensure
66
- tail_thread.kill if tail_thread
67
- puts 'Exiting'
68
- end
69
- end
@@ -1,16 +0,0 @@
1
- unless defined?(Mongrel)
2
- abort "PROBLEM: Mongrel is not available on your system (or not in your path)"
3
- end
4
-
5
- require 'rails/mongrel_server/commands'
6
-
7
- GemPlugin::Manager.instance.load "rails::mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE
8
-
9
- case ARGV[0] ||= 'start'
10
- when 'start', 'stop', 'restart'
11
- ARGV[0] = "rails::mongrelserver::#{ARGV[0]}"
12
- end
13
-
14
- if not Mongrel::Command::Registry.instance.run ARGV
15
- exit 1
16
- end
@@ -1,25 +0,0 @@
1
- require 'rbconfig'
2
- require 'commands/servers/base'
3
- require 'thin'
4
-
5
-
6
- options = ARGV.clone
7
- options.insert(0,'start') unless Thin::Runner.commands.include?(options[0])
8
-
9
- thin = Thin::Runner.new(options)
10
-
11
- puts "=> Rails #{Rails.version} application starting on http://#{thin.options[:address]}:#{thin.options[:port]}"
12
- puts "=> Ctrl-C to shutdown server"
13
-
14
- log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath
15
- open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log
16
- tail_thread = tail(log)
17
- trap(:INT) { exit }
18
-
19
- begin
20
- thin.run!
21
- ensure
22
- tail_thread.kill if tail_thread
23
- puts 'Exiting'
24
- end
25
-
@@ -1,66 +0,0 @@
1
- require 'webrick'
2
- require 'optparse'
3
- require 'commands/servers/base'
4
-
5
- OPTIONS = {
6
- :port => 3000,
7
- :ip => "0.0.0.0",
8
- :environment => (ENV['RAILS_ENV'] || "development").dup,
9
- :server_root => File.expand_path(RAILS_ROOT + "/public/"),
10
- :server_type => WEBrick::SimpleServer,
11
- :charset => "UTF-8",
12
- :mime_types => WEBrick::HTTPUtils::DefaultMimeTypes,
13
- :debugger => false
14
-
15
- }
16
-
17
- ARGV.options do |opts|
18
- script_name = File.basename($0)
19
- opts.banner = "Usage: ruby #{script_name} [options]"
20
-
21
- opts.separator ""
22
-
23
- opts.on("-p", "--port=port", Integer,
24
- "Runs Rails on the specified port.",
25
- "Default: 3000") { |v| OPTIONS[:port] = v }
26
- opts.on("-b", "--binding=ip", String,
27
- "Binds Rails to the specified ip.",
28
- "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
29
- opts.on("-e", "--environment=name", String,
30
- "Specifies the environment to run this server under (test/development/production).",
31
- "Default: development") { |v| OPTIONS[:environment] = v }
32
- opts.on("-m", "--mime-types=filename", String,
33
- "Specifies an Apache style mime.types configuration file to be used for mime types",
34
- "Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) }
35
-
36
- opts.on("-d", "--daemon",
37
- "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
38
- ) { OPTIONS[:server_type] = WEBrick::Daemon }
39
-
40
- opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true }
41
-
42
- opts.on("-c", "--charset=charset", String,
43
- "Set default charset for output.",
44
- "Default: UTF-8") { |v| OPTIONS[:charset] = v }
45
-
46
- opts.separator ""
47
-
48
- opts.on("-h", "--help",
49
- "Show this help message.") { puts opts; exit }
50
-
51
- opts.parse!
52
- end
53
-
54
- start_debugger if OPTIONS[:debugger]
55
-
56
- ENV["RAILS_ENV"] = OPTIONS[:environment]
57
- RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
58
-
59
- require RAILS_ROOT + "/config/environment"
60
- require 'webrick_server'
61
-
62
- OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
63
-
64
- puts "=> Rails #{Rails.version} application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
65
- puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
66
- DispatchServlet.dispatch(OPTIONS)
@@ -1,342 +0,0 @@
1
- # Copyright (c) 2005 Zed A. Shaw
2
- # You can redistribute it and/or modify it under the same terms as Ruby.
3
- #
4
- # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
5
- # for more information.
6
-
7
- require 'optparse'
8
- require 'yaml'
9
- require 'etc'
10
-
11
- require 'mongrel'
12
- require 'rails/mongrel_server/handler'
13
-
14
- module Rails
15
- module MongrelServer
16
- def self.send_signal(signal, pid_file)
17
- pid = open(pid_file).read.to_i
18
- print "Sending #{signal} to Mongrel at PID #{pid}..."
19
- begin
20
- Process.kill(signal, pid)
21
- rescue Errno::ESRCH
22
- puts "Process does not exist. Not running."
23
- end
24
-
25
- puts "Done."
26
- end
27
-
28
- class RailsConfigurator < Mongrel::Configurator
29
- def setup_mime_types
30
- mime = {}
31
-
32
- if defaults[:mime_map]
33
- Mongrel.log("Loading additional MIME types from #{defaults[:mime_map]}")
34
- mime = load_mime_map(defaults[:mime_map], mime)
35
- end
36
-
37
- mime.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) }
38
- end
39
-
40
- def mount_rails(prefix)
41
- ENV['RAILS_ENV'] = defaults[:environment]
42
- ::RAILS_ENV.replace(defaults[:environment]) if defined?(::RAILS_ENV)
43
-
44
- env_location = "#{defaults[:cwd]}/config/environment"
45
- require env_location
46
-
47
- ActionController::Base.relative_url_root = defaults[:prefix]
48
- uri prefix, :handler => Rails::MongrelServer::RailsHandler.new
49
- end
50
- end
51
-
52
- class Start < GemPlugin::Plugin "/commands"
53
- include Mongrel::Command::Base
54
-
55
- def configure
56
- options [
57
- ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
58
- ["-d", "--daemonize", "Run daemonized in the background", :@daemon, false],
59
- ['-p', '--port PORT', "Which port to bind to", :@port, 3000],
60
- ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
61
- ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
62
- ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "tmp/pids/mongrel.pid"],
63
- ['-n', '--num-procs INT', "Number of processors active before clients denied", :@num_procs, 1024],
64
- ['-o', '--timeout TIME', "Time to wait (in seconds) before killing a stalled thread", :@timeout, 60],
65
- ['-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients", :@throttle, 0],
66
- ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
67
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, RAILS_ROOT],
68
- ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
69
- ['-B', '--debug', "Enable debugging mode", :@debug, false],
70
- ['-C', '--config PATH', "Use a config file", :@config_file, nil],
71
- ['-S', '--script PATH', "Load the given file as an extra config script", :@config_script, nil],
72
- ['-G', '--generate PATH', "Generate a config file for use with -C", :@generate, nil],
73
- ['', '--user USER', "User to run as", :@user, nil],
74
- ['', '--group GROUP', "Group to run as", :@group, nil],
75
- ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil],
76
-
77
- ['-b', '--binding ADDR', "Address to bind to (deprecated, use -a)", :@address, "0.0.0.0"],
78
- ['-u', '--debugger', "Enable debugging mode (deprecated, use -B)", :@debug, false]
79
- ]
80
- end
81
-
82
- def validate
83
- if @config_file
84
- valid_exists?(@config_file, "Config file not there: #@config_file")
85
- return false unless @valid
86
- @config_file = File.expand_path(@config_file)
87
- load_config
88
- return false unless @valid
89
- end
90
-
91
- @cwd = File.expand_path(@cwd)
92
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
93
-
94
- # Change there to start, then we'll have to come back after daemonize
95
- Dir.chdir(@cwd)
96
-
97
- valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix
98
- valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file"
99
- valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file"
100
- valid_dir? @docroot, "Path to docroot not valid: #@docroot"
101
- valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
102
- valid_exists? @config_file, "Config file not there: #@config_file" if @config_file
103
- valid_dir? File.dirname(@generate), "Problem accessing directory to #@generate" if @generate
104
- valid_user? @user if @user
105
- valid_group? @group if @group
106
-
107
- return @valid
108
- end
109
-
110
- def run
111
- if @generate
112
- @generate = File.expand_path(@generate)
113
- Mongrel.log(:error, "** Writing config to \"#@generate\".")
114
- open(@generate, "w") {|f| f.write(settings.to_yaml) }
115
- Mongrel.log(:error, "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file.")
116
- exit 0
117
- end
118
-
119
- config = RailsConfigurator.new(settings) do
120
- defaults[:log] = $stdout if defaults[:environment] == 'development'
121
-
122
- Mongrel.log("=> Rails #{Rails.version} application starting on http://#{defaults[:host]}:#{defaults[:port]}")
123
-
124
- unless defaults[:daemon]
125
- Mongrel.log("=> Call with -d to detach")
126
- Mongrel.log("=> Ctrl-C to shutdown server")
127
- start_debugger if defaults[:debug]
128
- end
129
-
130
- if defaults[:daemon]
131
- if File.exist? defaults[:pid_file]
132
- Mongrel.log(:error, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.")
133
- Mongrel.log(:error, "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.")
134
- exit 1
135
- end
136
-
137
- daemonize
138
-
139
- Mongrel.log("Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.")
140
- Mongrel.log("Settings loaded from #{@config_file} (they override command line).") if @config_file
141
- end
142
-
143
- Mongrel.log("Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log")
144
-
145
- listener do
146
- prefix = defaults[:prefix] || '/'
147
-
148
- if defaults[:debug]
149
- Mongrel.log("Installing debugging prefixed filters. Look in log/mongrel_debug for the files.")
150
- debug(prefix)
151
- end
152
-
153
- setup_mime_types
154
- dir_handler = Mongrel::DirHandler.new(defaults[:docroot], false)
155
- dir_handler.passthrough_missing_files = true
156
-
157
- unless defaults[:environment] == 'production'
158
- Mongrel.log("Mounting DirHandler at #{prefix}...")
159
- uri prefix, :handler => dir_handler
160
- end
161
-
162
-
163
- Mongrel.log("Starting Rails with #{defaults[:environment]} environment...")
164
- Mongrel.log("Mounting Rails at #{prefix}...")
165
- mount_rails(prefix)
166
- Mongrel.log("Rails loaded.")
167
-
168
-
169
- Mongrel.log("Loading any Rails specific GemPlugins" )
170
- load_plugins
171
-
172
- if defaults[:config_script]
173
- Mongrel.log("Loading #{defaults[:config_script]} external config script")
174
- run_config(defaults[:config_script])
175
- end
176
-
177
- setup_signals
178
- end
179
- end
180
-
181
- config.run
182
- Mongrel.log("Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}")
183
-
184
- if config.defaults[:daemon]
185
- config.write_pid_file
186
- else
187
- Mongrel.log("Use CTRL-C to stop.")
188
- tail "log/#{config.defaults[:environment]}.log"
189
- end
190
-
191
- config.join
192
-
193
- if config.needs_restart
194
- unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
195
- cmd = "ruby #{__FILE__} start #{original_args.join(' ')}"
196
- Mongrel.log("Restarting with arguments: #{cmd}")
197
- config.stop(false, true)
198
- config.remove_pid_file
199
-
200
- if config.defaults[:daemon]
201
- system cmd
202
- else
203
- Mongrel.log(:error, "Can't restart unless in daemon mode.")
204
- exit 1
205
- end
206
- else
207
- Mongrel.log("Win32 does not support restarts. Exiting.")
208
- end
209
- end
210
- end
211
-
212
- def load_config
213
- settings = {}
214
- begin
215
- settings = YAML.load_file(@config_file)
216
- ensure
217
- Mongrel.log(:error, "** Loading settings from #{@config_file} (they override command line).") unless @daemon || settings[:daemon]
218
- end
219
-
220
- settings[:includes] ||= ["mongrel"]
221
-
222
- # Config file settings will override command line settings
223
- settings.each do |key, value|
224
- key = key.to_s
225
- if config_keys.include?(key)
226
- key = 'address' if key == 'host'
227
- self.instance_variable_set("@#{key}", value)
228
- else
229
- failure "Unknown configuration setting: #{key}"
230
- @valid = false
231
- end
232
- end
233
- end
234
-
235
- def config_keys
236
- @config_keys ||=
237
- %w(address host port cwd log_file pid_file environment docroot mime_map daemon debug includes config_script num_processors timeout throttle user group prefix)
238
- end
239
-
240
- def settings
241
- config_keys.inject({}) do |hash, key|
242
- value = self.instance_variable_get("@#{key}")
243
- key = 'host' if key == 'address'
244
- hash[key.to_sym] ||= value
245
- hash
246
- end
247
- end
248
-
249
- def start_debugger
250
- require_library_or_gem 'ruby-debug'
251
- Debugger.start
252
- Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
253
- Mongrel.log("=> Debugger enabled")
254
- rescue Exception
255
- Mongrel.log(:error, "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'")
256
- exit
257
- end
258
-
259
- def tail(log_file)
260
- cursor = File.size(log_file)
261
- last_checked = Time.now
262
- tail_thread = Thread.new do
263
- File.open(log_file, 'r') do |f|
264
- loop do
265
- f.seek cursor
266
- if f.mtime > last_checked
267
- last_checked = f.mtime
268
- contents = f.read
269
- cursor += contents.length
270
- print contents
271
- end
272
- sleep 1
273
- end
274
- end
275
- end
276
- tail_thread
277
- end
278
- end
279
-
280
- class Stop < GemPlugin::Plugin "/commands"
281
- include Mongrel::Command::Base
282
-
283
- def configure
284
- options [
285
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."],
286
- ['-f', '--force', "Force the shutdown (kill -9).", :@force, false],
287
- ['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"],
288
- ['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "log/mongrel.pid"]
289
- ]
290
- end
291
-
292
- def validate
293
- @cwd = File.expand_path(@cwd)
294
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
295
-
296
- Dir.chdir @cwd
297
-
298
- valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
299
- return @valid
300
- end
301
-
302
- def run
303
- if @force
304
- @wait.to_i.times do |waiting|
305
- exit(0) if not File.exist? @pid_file
306
- sleep 1
307
- end
308
-
309
- Mongrel::send_signal("KILL", @pid_file) if File.exist? @pid_file
310
- else
311
- Mongrel::send_signal("TERM", @pid_file)
312
- end
313
- end
314
- end
315
-
316
-
317
- class Restart < GemPlugin::Plugin "/commands"
318
- include Mongrel::Command::Base
319
-
320
- def configure
321
- options [
322
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, '.'],
323
- ['-P', '--pid FILE', "Where the PID file is located", :@pid_file, "log/mongrel.pid"]
324
- ]
325
- end
326
-
327
- def validate
328
- @cwd = File.expand_path(@cwd)
329
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
330
-
331
- Dir.chdir @cwd
332
-
333
- valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
334
- return @valid
335
- end
336
-
337
- def run
338
- MongrelServer::send_signal("USR2", @pid_file)
339
- end
340
- end
341
- end
342
- end