#!/usr/bin/env ruby## This file was generated by RubyGems.## The application 'railties' is installed as part of a gem, and# this file is here to facilitate running it.#require'rubygems'version=">= 0"ifARGV.firststr=ARGV.firststr=str.dup.force_encoding("BINARY")ifstr.respond_to?:force_encodingpstrifstr=~/\A_(.*)_\z/version=$1ARGV.shiftendendgem'railties',versionloadGem.bin_path('railties','rails',version)
require'rbconfig'require'rails/script_rails_loader'# If we are inside a Rails application this method performs an exec and thus# the rest of this script is not run.Rails::ScriptRailsLoader.exec_script_rails!require'rails/ruby_version_check'Signal.trap("INT"){puts;exit(1)}ifARGV.first=='plugin'ARGV.shiftrequire'rails/commands/plugin_new'elserequire'rails/commands/application'end
moduleRailsmoduleScriptRailsLoaderRUBY=File.join(*RbConfig::CONFIG.values_at("bindir","ruby_install_name"))+RbConfig::CONFIG["EXEEXT"]SCRIPT_RAILS=File.join('script','rails')defself.exec_script_rails!cwd=Dir.pwdreturnunlessin_rails_application?||in_rails_application_subdirectory?execRUBY,SCRIPT_RAILS,*ARGVifin_rails_application?...rescueSystemCallError# could not chdir, no problem just returnend...endend
#!/usr/bin/env ruby# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.APP_PATH=File.expand_path('../../config/application',__FILE__)requireFile.expand_path('../../config/boot',__FILE__)require'rails/commands'
when'server'# Change to the application's path if there is no config.ru file in current dir.# This allows us to run script/rails server from other directories, but still get# the main config.ru and properly set the tmp directory.Dir.chdir(File.expand_path('../../',APP_PATH))unlessFile.exists?(File.expand_path("config.ru"))require'rails/commands/server'Rails::Server.new.tap{|server|# We need to require application after the server sets environment,# otherwise the --environment option given to the server won't propagate.requireAPP_PATHDir.chdir(Rails.application.root)server.start}
defstarturl="#{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"=> Call with -d to detach"unlessoptions[:daemonize]trap(:INT){exit}puts"=> Ctrl-C to shutdown server"unlessoptions[:daemonize]#Create required tmp directories if not found%w(cache pids sessions sockets).eachdo|dir_to_make|FileUtils.mkdir_p(Rails.root.join('tmp',dir_to_make))endsuperensure# The '-h' option calls exit before @options is set.# If we call 'options' with it unset, we get double help banners.puts'Exiting'unless@options&&options[:daemonize]end
这时你就知道在 rails s 的时候显示的几行文字是从这里打印出来的了,最后他会调用 Rack::Server.start 方法,也就是父类方法.