Class: Rails::Command::ServerCommand
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base ,
Thor
|
|
Instance Chain:
|
|
Inherits: |
Rails::Command::Base
|
Defined in: | railties/lib/rails/commands/server/server_command.rb |
Constant Summary
-
DEFAULT_PIDFILE =
# File 'railties/lib/rails/commands/server/server_command.rb', line 103"tmp/pids/server.pid"
-
DEFAULT_PORT =
# File 'railties/lib/rails/commands/server/server_command.rb', line 1023000
-
RACK_HANDLERS =
Hard-coding a bunch of handlers here as we don’t have a public way of querying them from the
Rackup::Handler
registry.RACK_HANDLER_GEMS + %w(fastcgi lsws)
-
RACK_HANDLER_GEMS =
# File 'railties/lib/rails/commands/server/server_command.rb', line 96%w(cgi webrick scgi thin puma unicorn falcon)
-
RECOMMENDED_SERVER =
# File 'railties/lib/rails/commands/server/server_command.rb', line 100"puma"
Class Attribute Summary
Base
- Inherited
.bin, .bin?, | |
.engine? | Returns true when the app is a Rails engine. |
.exit_on_failure? |
Class Method Summary
- .new(args, local_options) ⇒ ServerCommand constructor
Base
- Inherited
.banner, | |
.base_name | Sets the base_name taking into account the current class namespace. |
.command_name | Return command name without namespaces. |
.default_command_root | Default file root to place extra files a command might need, placed one folder above the command file. |
.desc | Tries to get the description from a USAGE file one folder above the command root. |
.executable, | |
.hide_command! | Convenience method to hide this command from the available ones when running rails command. |
.namespace | Convenience method to get the namespace from the class name. |
.printing_commands, | |
.usage_path | Path to lookup a USAGE description in a file. |
.create_command | Allow the command method to be called perform. |
.namespaced_name, .resolve_path, .class_usage, | |
.help | Override Thor’s class-level help to also show the USAGE. |
.inherited, .perform |
Instance Attribute Summary
- #log_to_stdout? ⇒ Boolean readonly private
EnvironmentArgument
- Included
Instance Method Summary
- #perform
- #early_hints private
- #environment private
- #host private
- #pid private
- #port private
- #prepare_restart private
- #print_boot_information(server, url) private
- #rack_server_suggestion(server) private
- #restart_command private
- #user_supplied_options private
EnvironmentArgument
- Included
Actions
- Included
#boot_application!, #load_environment_config!, | |
#load_generators | See additional method definition at line 36. |
#load_tasks | See additional method definition at line 31. |
#require_application!, | |
#set_application_directory! | Change to the application’s path if there is no |
Constructor Details
.new(args, local_options) ⇒ ServerCommand
# File 'railties/lib/rails/commands/server/server_command.rb', line 125
def initialize(args, , *) super @original_options = - %w( --restart ) end
Instance Attribute Details
#log_to_stdout? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/commands/server/server_command.rb', line 239
def log_to_stdout? .fetch(:log_to_stdout) do [:daemon].blank? && environment == "development" end end
Instance Method Details
#early_hints (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 235
def early_hints [:early_hints] end
#environment (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 227
def environment [:environment] || Rails::Command.environment end
#host (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 217
def host if [:binding] [:binding] else default_host = environment == "development" ? "localhost" : "0.0.0.0" ENV.fetch("BINDING", default_host) end end
#perform
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 132
def perform set_application_directory! prepare_restart Rails::Server.new( ).tap do |server| # Require application after server sets environment to propagate # the --environment option. require APP_PATH Dir.chdir(Rails.application.root) if server.serveable? print_boot_information(server.server, server.served_url) after_stop_callback = -> { say "Exiting" unless [:daemon] } server.start(after_stop_callback) else say rack_server_suggestion( [:using]) end end end
#pid (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 245
def pid default_pidfile = environment == "development" ? DEFAULT_PIDFILE : nil pid = [:pid] || ENV["PIDFILE"] || default_pidfile File. (pid) if pid end
#port (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 213
def port [:port] || ENV.fetch("PORT", DEFAULT_PORT).to_i end
#prepare_restart (private)
[ GitHub ]#print_boot_information(server, url) (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 281
def print_boot_information(server, url) say <<~MSG #=> Booting #{ActiveSupport::Inflector.demodulize(server)} #=> Rails #{Rails.version} application starting in #{Rails.env} #{url} #=> Run `#{executable} --help` for more startup options MSG end
#rack_server_suggestion(server) (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 255
def rack_server_suggestion(server) if server.nil? <<~MSG Could not find a server gem. Maybe you need to add one to the Gemfile? gem "#{RECOMMENDED_SERVER}" Run `#{executable} --help` for more options. MSG elsif server.in?(RACK_HANDLER_GEMS) <<~MSG Could not load server "#{server}". Maybe you need to the add it to the Gemfile? gem "#{server}" Run `#{executable} --help` for more options. MSG else error = CorrectableNameError.new("Could not find server '#{server}'.", server, RACK_HANDLERS) <<~MSG #{error.} Run `#{executable} --help` for more options. MSG end end
#restart_command (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 231
def restart_command "#{executable} #{@original_options.join(" ")} --restart" end
#user_supplied_options (private)
[ GitHub ]# File 'railties/lib/rails/commands/server/server_command.rb', line 173
def @user_supplied_options ||= begin # Convert incoming options array to a hash of flags # ["-p3001", "-C", "--binding", "127.0.0.1"] # => {"-p"=>true, "-C"=>true, "--binding"=>true} user_flag = {} @original_options.each do |command| if command.start_with?("--") option = command.split("=")[0] user_flag[option] = true elsif command =~ /\A(-.)/ user_flag[Regexp.last_match[0]] = true end end # Collect all options that the user has explicitly defined so we can # differentiate them from defaults = [] self.class. .select do |key, option| if option.aliases.any? { |name| user_flag[name] } || user_flag["--#{option.name}"] name = option.name.to_sym case name when :port name = :Port when :binding name = :Host when :dev_caching name = :caching when :daemonize name = :daemon end << name end end << :Host if ENV["HOST"] || ENV["BINDING"] << :Port if ENV["PORT"] << :pid if ENV["PIDFILE"] .uniq end end