mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract method refactoring for Rails::Server#start
This commit is contained in:
parent
f8e5022c73
commit
919fafa54b
1 changed files with 38 additions and 24 deletions
|
@ -61,30 +61,10 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
|
print_boot_information
|
||||||
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
|
trap_interrupt_and_print_interrupt_information
|
||||||
puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
|
create_tmp_directories
|
||||||
puts "=> Run `rails server -h` for more startup options"
|
log_to_stdout if options[:log_stdout]
|
||||||
if options[:Host].to_s.match(/0\.0\.0\.0/)
|
|
||||||
puts "=> Notice: server is listening on all interfaces (#{options[:Host]}). Consider using 127.0.0.1 (--binding option)"
|
|
||||||
end
|
|
||||||
trap(:INT) { exit }
|
|
||||||
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
|
|
||||||
|
|
||||||
#Create required tmp directories if not found
|
|
||||||
%w(cache pids sessions sockets).each do |dir_to_make|
|
|
||||||
FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make))
|
|
||||||
end
|
|
||||||
|
|
||||||
if options[:log_stdout]
|
|
||||||
wrapped_app # touch the app so the logger is set up
|
|
||||||
|
|
||||||
console = ActiveSupport::Logger.new($stdout)
|
|
||||||
console.formatter = Rails.logger.formatter
|
|
||||||
console.level = Rails.logger.level
|
|
||||||
|
|
||||||
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
|
||||||
end
|
|
||||||
|
|
||||||
super
|
super
|
||||||
ensure
|
ensure
|
||||||
|
@ -124,5 +104,39 @@ module Rails
|
||||||
config: File.expand_path("config.ru")
|
config: File.expand_path("config.ru")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def print_boot_information
|
||||||
|
url = "#{ options[:SSLEnable] ? 'https' : 'http' }://#{ options[:Host] }:#{ options[:Port] }"
|
||||||
|
puts "=> Booting #{ ActiveSupport::Inflector.demodulize(server) }"
|
||||||
|
puts "=> Rails #{ Rails.version } application starting in #{ Rails.env } on #{ url }"
|
||||||
|
puts "=> Run `rails server -h` for more startup options"
|
||||||
|
|
||||||
|
if options[:Host].to_s.match(/0\.0\.0\.0/)
|
||||||
|
puts "=> Notice: server is listening on all interfaces (#{ options[:Host] }). Consider using 127.0.0.1 (--binding option)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def trap_interrupt_and_print_interrupt_information
|
||||||
|
trap(:INT) { exit }
|
||||||
|
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_tmp_directories
|
||||||
|
%w(cache pids sessions sockets).each do |dir_to_make|
|
||||||
|
FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_to_stdout
|
||||||
|
wrapped_app # touch the app so the logger is set up
|
||||||
|
|
||||||
|
console = ActiveSupport::Logger.new($stdout)
|
||||||
|
console.formatter = Rails.logger.formatter
|
||||||
|
console.level = Rails.logger.level
|
||||||
|
|
||||||
|
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue