From 9af6601a46ec6afeafc61597eb10bdc7f175370d Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 10 Mar 2018 19:43:31 +0900 Subject: Do not show unnecessary message during server startup Currently, `Exiting` is showed during server startup. ``` ./bin/rails s => Booting Puma => Rails 6.0.0.alpha application starting in development => Run `rails server --help` for more startup options Exiting Puma starting in single mode... * Version 3.11.2 (ruby 2.5.0-p0), codename: Love Song ``` This is because processing at server stop is passed as a block, and `Rack::Serve#start` receives a block and executes it during startup processing. https://github.com/rack/rack/blob/50db1ffdf8b98503fb7c6e6648622b5d7d78d58e/lib/rack/server.rb#L258 In order to avoid this, stop processing is passed as argument. --- railties/lib/rails/commands/server/server_command.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 64fb912b51..8588e2fd64 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -43,15 +43,15 @@ module Rails ENV["RAILS_ENV"] ||= options[:environment] end - def start + def start(after_stop_callback = nil) trap(:INT) { exit } create_tmp_directories setup_dev_caching log_to_stdout if options[:log_stdout] - super + super() ensure - yield + after_stop_callback.call if after_stop_callback end def serveable? # :nodoc: @@ -157,9 +157,8 @@ module Rails if server.serveable? print_boot_information(server.server, server.served_url) - server.start do - say "Exiting" unless options[:daemon] - end + after_stop_callback = -> { say "Exiting" unless options[:daemon] } + server.start(after_stop_callback) else say rack_server_suggestion(using) end -- cgit v1.2.3