New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce explicit rails server handler option #32058

Merged
merged 2 commits into from Mar 4, 2018

Conversation

Projects
None yet
6 participants
@gsamokovarov
Contributor

gsamokovarov commented Feb 19, 2018

I mistype rails server production instead of rails server -e production expecting to lunch a server in the production environment
all the time. However, the signature of rails server --help is:

Usage:
  rails server [puma, thin etc] [options]

This means that the production argument is being interpreted as a Rack
server handler like Puma, Thin or Unicorn.

Should we argue for the rails server production? I'm not sure of the
reasons, but the rails console production behavior was deprecated in:
#29358, so parity with the existing
rails console production usage may not hold anymore.

In any case, this PR introduces an explicit option for the Rack servers
configuration. I call them --handlers (or -x for short, as -h is
already as the shortcut for --help) to avoid the rails server --server tantrum.

The new interface of rails server is:

Usage:
  rails server [handler] [options]

Options:
  -p, [--port=port]                        # Runs Rails on the specified port - defaults to 3000.
  -b, [--binding=IP]                       # Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.
  -c, [--config=file]                      # Uses a custom rackup configuration.
                                           # Default: config.ru
  -d, [--daemon], [--no-daemon]            # Runs server as a Daemon.
  -e, [--environment=name]                 # Specifies the environment to run this server under (development/test/production).
  -x, [--handler=name]                     # Specifies the Rack server to run the application (thin/puma/webrick).
  -P, [--pid=PID]                          # Specifies the PID file.
                                           # Default: tmp/pids/server.pid
  -C, [--dev-caching], [--no-dev-caching]  # Specifies whether to perform caching in development.
      [--early-hints], [--no-early-hints]  # Enables HTTP/2 early hints.

As a bonus, if you mistype the handler, you'll get an auto-correction
message:

$ rails s tin
Could not find handler 'tin'. Maybe you meant 'thin' or 'cgi'?
Run `rails server --help` for more options.
@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Feb 19, 2018

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

rails-bot commented Feb 19, 2018

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

@gsamokovarov

This comment has been minimized.

Show comment
Hide comment
@gsamokovarov

gsamokovarov Feb 19, 2018

Contributor

The previous error was:

$ rails server production
Exiting
Traceback (most recent call last):
	36: from bin/rails:3:in `<main>'
	35: from bin/rails:3:in `load'
	34: from /Users/genadi/Development/bithost/dashboard.bithost.io/bin/spring:15:in `<top (required)>'
	33: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
	32: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
	31: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
	30: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
	29: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
	28: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
	27: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
	26: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
	25: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
	24: from /Users/genadi/Development/bithost/dashboard.bithost.io/bin/rails:9:in `<top (required)>'
	23: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `require'
	22: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:249:in `load_dependency'
	21: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `block in require'
	20: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
	19: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
	18: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands.rb:18:in `<main>'
	17: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/command.rb:46:in `invoke'
	16: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/command/base.rb:65:in `perform'
	15: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	14: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	13: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	12: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:142:in `perform'
	11: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:142:in `tap'
	10: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
	 9: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:47:in `start'
	 8: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:76:in `print_boot_information'
	 7: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:105:in `use_puma?'
	 6: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.4/lib/rack/server.rb:301:in `server'
	 5: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.4/lib/rack/handler.rb:16:in `get'
	 4: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.4/lib/rack/handler.rb:74:in `try_require'
	 3: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `require'
	 2: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:249:in `load_dependency'
	 1: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `block in require'
/Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:19:in `require': cannot load such file -- rack/handler/production (LoadError)
Contributor

gsamokovarov commented Feb 19, 2018

The previous error was:

$ rails server production
Exiting
Traceback (most recent call last):
	36: from bin/rails:3:in `<main>'
	35: from bin/rails:3:in `load'
	34: from /Users/genadi/Development/bithost/dashboard.bithost.io/bin/spring:15:in `<top (required)>'
	33: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
	32: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
	31: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
	30: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
	29: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
	28: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
	27: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
	26: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
	25: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
	24: from /Users/genadi/Development/bithost/dashboard.bithost.io/bin/rails:9:in `<top (required)>'
	23: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `require'
	22: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:249:in `load_dependency'
	21: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `block in require'
	20: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
	19: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
	18: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands.rb:18:in `<main>'
	17: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/command.rb:46:in `invoke'
	16: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/command/base.rb:65:in `perform'
	15: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	14: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	13: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	12: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:142:in `perform'
	11: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:142:in `tap'
	10: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
	 9: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:47:in `start'
	 8: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:76:in `print_boot_information'
	 7: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0.rc1/lib/rails/commands/server/server_command.rb:105:in `use_puma?'
	 6: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.4/lib/rack/server.rb:301:in `server'
	 5: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.4/lib/rack/handler.rb:16:in `get'
	 4: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.4/lib/rack/handler.rb:74:in `try_require'
	 3: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `require'
	 2: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:249:in `load_dependency'
	 1: from /Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0.rc1/lib/active_support/dependencies.rb:283:in `block in require'
/Users/genadi/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:19:in `require': cannot load such file -- rack/handler/production (LoadError)
@kaspth

👍 to adding the argument validation. But I don't understand why it follows that we should turn the server positional arg into an option?

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/test/commands/server_test.rb
Show outdated Hide outdated railties/test/commands/server_test.rb
@matthewd

This comment has been minimized.

Show comment
Hide comment
@matthewd

matthewd Feb 24, 2018

Member

@kaspth we removed the positional parameter for console in #29358; I don't see why we'd want to retain it for server but not console.

(Specifically, given that we can only load a handler that's available in the Gemfile, and that we automatically load the first handler that's available in the Gemfile, it seems pretty rare to me for people to have cause to name a handler at all.)

Member

matthewd commented Feb 24, 2018

@kaspth we removed the positional parameter for console in #29358; I don't see why we'd want to retain it for server but not console.

(Specifically, given that we can only load a handler that's available in the Gemfile, and that we automatically load the first handler that's available in the Gemfile, it seems pretty rare to me for people to have cause to name a handler at all.)

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Feb 24, 2018

Member

@matthewd sure, but that was for the environment, no? I thought bin/rails dbconsole replicant -e production was still possible?

Anyway, you're right that passing it manually is probably a minority case, so lets go with the deprecation — and --using 👍

Member

kaspth commented Feb 24, 2018

@matthewd sure, but that was for the environment, no? I thought bin/rails dbconsole replicant -e production was still possible?

Anyway, you're right that passing it manually is probably a minority case, so lets go with the deprecation — and --using 👍

@gsamokovarov

This comment has been minimized.

Show comment
Hide comment
@gsamokovarov

gsamokovarov Feb 25, 2018

Contributor

I have changed the option to --using and deprecated the passing of the Rack server as a regular argument.

Contributor

gsamokovarov commented Feb 25, 2018

I have changed the option to --using and deprecated the passing of the Rack server as a regular argument.

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Feb 25, 2018

Member

This is probably for another time, but… I just realized that now we're on 2.3+ we could leverage the DidYouMean gem's spellchecker: https://github.com/yuki24/did_you_mean/blob/4d4484940cdab27566538e6453ff428d39fbad7a/lib/did_you_mean/spell_checker.rb#L8

unless HANDLERS.include?(options[:using])
  DidYouMean::SpellChecker.new(HANDLERS).correct(options[:using])
end
irb(main):002:0> c = DidYouMean::SpellChecker.new(dictionary: [ 'cgi', 'puma' ])
=> #<DidYouMean::SpellChecker:0x00007fa055866ee0 @dictionary=["cgi", "puma"]>
irb(main):003:0> c.correct('cgy')
=> ["cgi"]
irb(main):004:0> c.correct('pumma')
=> ["puma"]

We could also remove Rails' Levenshtein distance method from other places.

Member

kaspth commented Feb 25, 2018

This is probably for another time, but… I just realized that now we're on 2.3+ we could leverage the DidYouMean gem's spellchecker: https://github.com/yuki24/did_you_mean/blob/4d4484940cdab27566538e6453ff428d39fbad7a/lib/did_you_mean/spell_checker.rb#L8

unless HANDLERS.include?(options[:using])
  DidYouMean::SpellChecker.new(HANDLERS).correct(options[:using])
end
irb(main):002:0> c = DidYouMean::SpellChecker.new(dictionary: [ 'cgi', 'puma' ])
=> #<DidYouMean::SpellChecker:0x00007fa055866ee0 @dictionary=["cgi", "puma"]>
irb(main):003:0> c.correct('cgy')
=> ["cgi"]
irb(main):004:0> c.correct('pumma')
=> ["puma"]

We could also remove Rails' Levenshtein distance method from other places.

@kaspth

Getting real close!

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
@gsamokovarov

This comment has been minimized.

Show comment
Hide comment
@gsamokovarov

gsamokovarov Feb 25, 2018

Contributor

@kaspth, I think I'll be able to get the printing out of the Rails::Server class and put it into the command. I had a couple of naive attempts but part of the printing needs to know about whether Rails::Server#server is puma and this crosses some boundaries, but I'm sure we can get it.

As for moving the handler suggestion logic entirely into the Rails::Command::ServerCommand it may not be as pretty because of the current Rails::Command::Behavior concern ahem, behavior 😅, that introduces the levenstein_distance method as private class method, which is pretty specific to the first place it was used.

Contributor

gsamokovarov commented Feb 25, 2018

@kaspth, I think I'll be able to get the printing out of the Rails::Server class and put it into the command. I had a couple of naive attempts but part of the printing needs to know about whether Rails::Server#server is puma and this crosses some boundaries, but I'm sure we can get it.

As for moving the handler suggestion logic entirely into the Rails::Command::ServerCommand it may not be as pretty because of the current Rails::Command::Behavior concern ahem, behavior 😅, that introduces the levenstein_distance method as private class method, which is pretty specific to the first place it was used.

Show outdated Hide outdated railties/CHANGELOG.md
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
@gsamokovarov

This comment has been minimized.

Show comment
Hide comment
@gsamokovarov

gsamokovarov Feb 26, 2018

Contributor

Friends, I have moved the printing out of Rails::Server. Want to take another look? There are still some funky bits, but I think we're getting there.

Contributor

gsamokovarov commented Feb 26, 2018

Friends, I have moved the printing out of Rails::Server. Want to take another look? There are still some funky bits, but I think we're getting there.

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
@kaspth

I really like where you took this in this round, Genadi! Hadn't thought of extracting all the printing to the command.

Also don't be afraid to say if you've had enough review rounds and would rather focus on wrapping it up. Then we'll find a way to cut it.

I've been using this case to ease back into the command infrastructure and what exactly the responsibility of a command should be. So if it feels like it's playing around a little bit — that's because it is! 😄

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
@@ -132,27 +155,34 @@ class ServerCommand < Base # :nodoc:
def initialize(args = [], local_options = {}, config = {})
@original_options = local_options
super
@server = self.args.shift

This comment has been minimized.

@kaspth

kaspth Feb 26, 2018

Member

I think it would be better and clearer to do this than the @_using construct:

super

deprecate_positional_using if @using
@using ||= options[:using]

@log_stdout =
@kaspth

kaspth Feb 26, 2018

Member

I think it would be better and clearer to do this than the @_using construct:

super

deprecate_positional_using if @using
@using ||= options[:using]

@log_stdout =
@gsamokovarov

This comment has been minimized.

Show comment
Hide comment
@gsamokovarov

gsamokovarov Feb 27, 2018

Contributor

Don't worry Kasper I'm having fun as well. 😀

Contributor

gsamokovarov commented Feb 27, 2018

Don't worry Kasper I'm having fun as well. 😀

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
@kaspth

kaspth approved these changes Mar 3, 2018

Really like how this turned out 👍

Feels right that the command handles the error printing and the server is more focused on its own boot.

Some minor nits left, then I'll merge.

server.start
if server.serveable?
print_boot_information(server.server, server.served_url)

This comment has been minimized.

@kaspth

kaspth Mar 3, 2018

Member

Let's put a newline after this.

@kaspth

kaspth Mar 3, 2018

Member

Let's put a newline after this.

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
<<~MSG
Could not find server "#{server}". Maybe you meant #{suggestions.first} or #{suggestions.second}?
Run `rails server --help` for more options.
MSG

This comment has been minimized.

@kaspth

kaspth Mar 3, 2018

Member

For another time: I could totally see us enriching Thor's argument/option with a :suggestions to get messages like this for free. E.g.:

class_option :using, aliases: "-u", type: :string, suggestions: RACK_SERVERS,
  desc: "Specifies the Rack server used to run the application (thin/puma/webrick).", banner: :name
@kaspth

kaspth Mar 3, 2018

Member

For another time: I could totally see us enriching Thor's argument/option with a :suggestions to get messages like this for free. E.g.:

class_option :using, aliases: "-u", type: :string, suggestions: RACK_SERVERS,
  desc: "Specifies the Rack server used to run the application (thin/puma/webrick).", banner: :name
trap(:INT) { exit }
create_tmp_directories
setup_dev_caching
log_to_stdout if options[:log_stdout]
super
ensure
# The '-h' option calls exit before @options is set.
# If we call 'options' with it unset, we get double help banners.

This comment has been minimized.

@kaspth

kaspth Mar 3, 2018

Member

👍, dig that we got rid of these comments.

@kaspth

kaspth Mar 3, 2018

Member

👍, dig that we got rid of these comments.

Show outdated Hide outdated railties/lib/rails/commands/server/server_command.rb
@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Mar 3, 2018

Member

Oh, needs a commit squash and rebase too! Normally we'd want 1 commit, but I'll grant you a commit for the spellchecker change first, then one for the server changes after that if you want. 1 commit is fine too 👍

Member

kaspth commented Mar 3, 2018

Oh, needs a commit squash and rebase too! Normally we'd want 1 commit, but I'll grant you a commit for the spellchecker change first, then one for the server changes after that if you want. 1 commit is fine too 👍

gsamokovarov added some commits Feb 19, 2018

Introduce explicit rails server handler option
I mistype `rails server production` instead of `rails server -e
production` expecting to lunch a server in the production environment
all the time. However, the signature of `rails server --help` is:

```
Usage:
  rails server [puma, thin etc] [options]
```

This means that the `production` argument is being interpreted as a Rack
server handler like Puma, Thin or Unicorn.

Should we argue for the `rails server production`? I'm not sure of the
reasons, but the `rails console production` behavior was deprecated in:
#29358, so parity with the existing
`rails console production` usage may not hold anymore.

In any case, this PR introduces an explicit option for the Rack servers
configuration. The option is called `--using` (or `-u` for short) to
avoid the `rails server --server` tantrum.

The new interface of `rails server` is:

```
Usage:
  rails server [using] [options]

Options:
  -p, [--port=port]                        # Runs Rails on the specified port - defaults to 3000.
  -b, [--binding=IP]                       # Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.
  -c, [--config=file]                      # Uses a custom rackup configuration.
                                           # Default: config.ru
  -d, [--daemon], [--no-daemon]            # Runs server as a Daemon.
  -e, [--environment=name]                 # Specifies the environment to run this server under (development/test/production).
  -u, [--using=name]                       # Specifies the Rack server used to run the application (thin/puma/webrick).
  -P, [--pid=PID]                          # Specifies the PID file.
                                           # Default: tmp/pids/server.pid
  -C, [--dev-caching], [--no-dev-caching]  # Specifies whether to perform caching in development.
      [--early-hints], [--no-early-hints]  # Enables HTTP/2 early hints.
```

As a bonus, if you mistype the server to use, you'll get an
auto-correction message:

```
$ rails s tin
Could not find handler "tin". Maybe you meant "thin" or "cgi"?
Run `rails server --help` for more options.
```
@gsamokovarov

This comment has been minimized.

Show comment
Hide comment
@gsamokovarov

gsamokovarov Mar 4, 2018

Contributor

Kasper, I have searched for Rails::Server usage in GitHub, but the two keywords: rails and server yield a lot of uninteresting results for us. See https://help.github.com/articles/searching-code:

You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]. The search will simply ignore these symbols.

This means that we cannot match Rails::Server exactly, because of the : character ignore and we can't be exactly sure whether it's used. I left the # :nodoc: only to the serveable? method.

Contributor

gsamokovarov commented Mar 4, 2018

Kasper, I have searched for Rails::Server usage in GitHub, but the two keywords: rails and server yield a lot of uninteresting results for us. See https://help.github.com/articles/searching-code:

You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]. The search will simply ignore these symbols.

This means that we cannot match Rails::Server exactly, because of the : character ignore and we can't be exactly sure whether it's used. I left the # :nodoc: only to the serveable? method.

@kaspth kaspth merged commit f4ddbff into rails:master Mar 4, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
codeclimate All good!
Details
@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Mar 4, 2018

Member

Fine with me! Really glad how this turned out 👏

Member

kaspth commented Mar 4, 2018

Fine with me! Really glad how this turned out 👏

@gsamokovarov

This comment has been minimized.

Show comment
Hide comment
@gsamokovarov

gsamokovarov Mar 4, 2018

Contributor

Thanks for the review! 🙇‍♂️

Contributor

gsamokovarov commented Mar 4, 2018

Thanks for the review! 🙇‍♂️

@gsamokovarov gsamokovarov deleted the gsamokovarov:rails-server-x-option branch Mar 4, 2018

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Jul 7, 2018

Member

Did some work on the server command a0061d2...1d97b8f and realized I forgot to backport this to 5-2-stable 🤭

Member

kaspth commented Jul 7, 2018

Did some work on the server command a0061d2...1d97b8f and realized I forgot to backport this to 5-2-stable 🤭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment