diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 5 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 39 | ||||
-rw-r--r-- | railties/lib/rails/commands/runner.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/commands/server.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/dev_caching.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/tasks/restart.rake | 1 | ||||
-rw-r--r-- | railties/test/application/rake/dev_test.rb | 9 | ||||
-rw-r--r-- | railties/test/application/rake/restart_test.rb | 9 | ||||
-rw-r--r-- | railties/test/commands/server_test.rb | 14 |
10 files changed, 77 insertions, 19 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 7193238e83..52c2e0743c 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* Make `rails restart` command work with Puma by passing the restart command + which Puma can use to restart rails server. + + *Prathamesh Sonpatki* + * The application generator writes a new file `config/spring.rb`, which tells Spring to watch additional common files. diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 65cff1561a..0aceee1c9a 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -70,7 +70,7 @@ module Rails def serve_static_files ActiveSupport::Deprecation.warn <<-eow.strip_heredoc `serve_static_files` is deprecated and will be removed in Rails 5.1. - Please use `public_file_server.enabled` instead. + Please use `config.public_file_server.enabled` instead. eow @public_file_server.enabled @@ -79,7 +79,7 @@ module Rails def serve_static_files=(value) ActiveSupport::Deprecation.warn <<-eow.strip_heredoc `serve_static_files` is deprecated and will be removed in Rails 5.1. - Please use `public_file_server.enabled = #{value}` instead. + Please use `config.public_file_server.enabled = #{value}` instead. eow @public_file_server.enabled = value diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 34f2265108..0aed6c1351 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -62,18 +62,36 @@ module Rails ActiveSupport.run_load_hooks(:after_initialize, self) end + class MutexHook + def initialize(mutex = Mutex.new) + @mutex = mutex + end + + def run + @mutex.lock + end + + def complete(_state) + @mutex.unlock + end + end + + module InterlockHook + def self.run + ActiveSupport::Dependencies.interlock.start_running + end + + def self.complete(_state) + ActiveSupport::Dependencies.interlock.done_running + end + end + initializer :configure_executor_for_concurrency do |app| if config.allow_concurrency == false # User has explicitly opted out of concurrent request # handling: presumably their code is not threadsafe - mutex = Mutex.new - app.executor.to_run(prepend: true) do - mutex.lock - end - app.executor.to_complete(:after) do - mutex.unlock - end + app.executor.register_hook(MutexHook.new, outer: true) elsif config.allow_concurrency == :unsafe # Do nothing, even if we know this is dangerous. This is the @@ -86,12 +104,7 @@ module Rails # Without cache_classes + eager_load, the load interlock # is required for proper operation - app.executor.to_run(prepend: true) do - ActiveSupport::Dependencies.interlock.start_running - end - app.executor.to_complete(:after) do - ActiveSupport::Dependencies.interlock.done_running - end + app.executor.register_hook(InterlockHook, outer: true) end end end diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 5844e9037c..f9c183ac86 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -2,6 +2,7 @@ require 'optparse' options = { environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup } code_or_file = nil +command = 'bin/rails runner' if ARGV.first.nil? ARGV.push "-h" @@ -34,7 +35,7 @@ ARGV.clone.options do |opts| opts.separator "" opts.separator "You can also use runner as a shebang line for your executables:" opts.separator " -------------------------------------------------------------" - opts.separator " #!/usr/bin/env #{File.expand_path($0)} runner" + opts.separator " #!/usr/bin/env #{File.expand_path(command)}" opts.separator "" opts.separator " Product.all.each { |p| p.price *= 2 ; p.save! }" opts.separator " -------------------------------------------------------------" @@ -52,7 +53,7 @@ Rails.application.require_environment! Rails.application.load_runner if code_or_file.nil? - $stderr.puts "Run '#{$0} -h' for help." + $stderr.puts "Run '#{command} -h' for help." exit 1 elsif File.exist?(code_or_file) $0 = code_or_file @@ -62,7 +63,7 @@ else eval(code_or_file, binding, __FILE__, __LINE__) rescue SyntaxError, NameError $stderr.puts "Please specify a valid ruby command or the path of a script to run." - $stderr.puts "Run '#{$0} -h' for help." + $stderr.puts "Run '#{command} -h' for help." exit 1 end end diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index c2434d62e2..7418dff18b 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -94,7 +94,8 @@ module Rails environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup, daemonize: false, caching: nil, - pid: Options::DEFAULT_PID_PATH + pid: Options::DEFAULT_PID_PATH, + restart_cmd: restart_command }) end @@ -130,5 +131,9 @@ module Rails Rails.logger.extend(ActiveSupport::Logger.broadcast(console)) end end + + def restart_command + "bin/rails server #{ARGV.join(' ')}" + end end end diff --git a/railties/lib/rails/dev_caching.rb b/railties/lib/rails/dev_caching.rb index 4760010851..3c20164f0f 100644 --- a/railties/lib/rails/dev_caching.rb +++ b/railties/lib/rails/dev_caching.rb @@ -15,6 +15,7 @@ module Rails end FileUtils.touch 'tmp/restart.txt' + FileUtils.rm_f('tmp/pids/server.pid') end def enable_by_argument(caching) diff --git a/railties/lib/rails/tasks/restart.rake b/railties/lib/rails/tasks/restart.rake index f36c86d81b..7e15bb55a1 100644 --- a/railties/lib/rails/tasks/restart.rake +++ b/railties/lib/rails/tasks/restart.rake @@ -2,4 +2,5 @@ desc "Restart app by touching tmp/restart.txt" task :restart do FileUtils.mkdir_p('tmp') FileUtils.touch('tmp/restart.txt') + FileUtils.rm_f('tmp/pids/server.pid') end diff --git a/railties/test/application/rake/dev_test.rb b/railties/test/application/rake/dev_test.rb index 59b46c6e79..deb9bc8dee 100644 --- a/railties/test/application/rake/dev_test.rb +++ b/railties/test/application/rake/dev_test.rb @@ -29,6 +29,15 @@ module ApplicationTests assert_match(/Development mode is no longer being cached/, output) end end + + test 'dev:cache removes server.pid also' do + Dir.chdir(app_path) do + FileUtils.mkdir_p("tmp/pids") + FileUtils.touch("tmp/pids/server.pid") + `rake dev:cache` + assert_not File.exist?("tmp/pids/server.pid") + end + end end end end diff --git a/railties/test/application/rake/restart_test.rb b/railties/test/application/rake/restart_test.rb index 4cae199e6b..30f662a9be 100644 --- a/railties/test/application/rake/restart_test.rb +++ b/railties/test/application/rake/restart_test.rb @@ -34,6 +34,15 @@ module ApplicationTests assert File.exist?('tmp/restart.txt') end end + + test 'rake restart removes server.pid also' do + Dir.chdir(app_path) do + FileUtils.mkdir_p("tmp/pids") + FileUtils.touch("tmp/pids/server.pid") + `rake restart` + assert_not File.exist?("tmp/pids/server.pid") + end + end end end end diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb index 964b9a44de..38a1605d1f 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -118,4 +118,18 @@ class Rails::ServerTest < ActiveSupport::TestCase assert_equal old_default_options, server.default_options end end + + def test_restart_command_contains_customized_options + original_args = ARGV.dup + args = ["-p", "4567"] + ARGV.replace args + + options = Rails::Server::Options.new.parse! args + server = Rails::Server.new options + expected = "bin/rails server -p 4567" + + assert_equal expected, server.default_options[:restart_cmd] + ensure + ARGV.replace original_args + end end |