Allow padrino start to take handler specific options #1452

Merged
merged 2 commits into from Oct 16, 2013

Conversation

Projects
None yet
3 participants
@dariocravero
Contributor

dariocravero commented Oct 14, 2013

Modified padrino start to take an extra --options (-O) parameter to pass options to the rack handler.

For instance, with puma you can now do:
bundle exec padrino s -O Threads=3:16 and the server will start with 3 to 16 threads.

This implementation follows the same syntax that rackup uses for compatibility.

Also implemented --server_options to print out the supported options for the selected handler (application server).

This has been requested a couple of times, the latest in #1451.

I'd still recommend people to run their applications through the application server directly -e.g., puma, unicorn, thin...- instead of using this but it might come in handy for development.

Thoughts @padrino/core-members?

Modified `padrino start` to take an extra `--options` (`-O`) parameter
to pass options to the rack handler.

For instance, with `puma` you can now do:
`bundle exec padrino s -O Threads=3:16` and the server will start with 3
to 16 threads.

This implementation follows the same syntax that
[rackup](https://github.com/rack/rack/blob/master/lib/rack/server.rb\#L100) uses for
compatibility.

Also implemented --server_options to print out the supported options for
the selected handler (application server).

This has been requested a couple of times, the latest in #1451.

I'd still recommend people to run their applications through the
application server directly -e.g., puma, unicorn, thin...- instead of
using this but it might come in handy for development.
padrino-core/lib/padrino-core/server.rb
@@ -31,6 +31,7 @@ def self.start(app, opts={})
FileUtils.mkdir_p(File.dirname(options[:pid]))
end
options[:server] = detect_rack_handler if options[:server].blank?
+ options.merge!(Hash[*options.delete(:options).map {|opt| opt.split('=',2)}.flatten].symbolize_keys!) if options[:options].is_a?(Array)

This comment has been minimized.

@Ortuna

Ortuna Oct 14, 2013

Member

Might I suggest breaking this out into a few lines? Looks very intimidating at first glance.

@Ortuna

Ortuna Oct 14, 2013

Member

Might I suggest breaking this out into a few lines? Looks very intimidating at first glance.

This comment has been minimized.

@dariocravero

dariocravero Oct 15, 2013

Contributor

Yeah, that makes sense... they only question is how :) Maybe?:

if options[:options].is_a?(Array)
  server_options = Hash[*options.delete(:options).map {|opt| opt.split('=',2)}.flatten].symbolize_keys!
  options.merge!(server_options)
end

or

if options[:options].is_a?(Array)
  parsed_server_options = options.delete(:options).map { |opt| opt.split('=', 2) }.flatten
  server_options = Hash[*parsed_options].symbolize_keys!
  options.merge!(server_options)
end
@dariocravero

dariocravero Oct 15, 2013

Contributor

Yeah, that makes sense... they only question is how :) Maybe?:

if options[:options].is_a?(Array)
  server_options = Hash[*options.delete(:options).map {|opt| opt.split('=',2)}.flatten].symbolize_keys!
  options.merge!(server_options)
end

or

if options[:options].is_a?(Array)
  parsed_server_options = options.delete(:options).map { |opt| opt.split('=', 2) }.flatten
  server_options = Hash[*parsed_options].symbolize_keys!
  options.merge!(server_options)
end

This comment has been minimized.

@Ortuna

Ortuna Oct 15, 2013

Member
if options[:options].is_a?(Array)
  parsed_server_options = options.delete(:options).map { |opt| opt.split('=', 2) }.flatten
  server_options = Hash[*parsed_options].symbolize_keys!
  options.merge!(server_options)
end

👍
More than acceptable

@Ortuna

Ortuna Oct 15, 2013

Member
if options[:options].is_a?(Array)
  parsed_server_options = options.delete(:options).map { |opt| opt.split('=', 2) }.flatten
  server_options = Hash[*parsed_options].symbolize_keys!
  options.merge!(server_options)
end

👍
More than acceptable

@Ortuna

This comment has been minimized.

Show comment
Hide comment
@Ortuna

Ortuna Oct 14, 2013

Member

👍

Member

Ortuna commented Oct 14, 2013

👍

@ujifgc

This comment has been minimized.

Show comment
Hide comment
@ujifgc

ujifgc Oct 15, 2013

Member

@Ortuna you can push to padrino-start-accepts-handler-options

Member

ujifgc commented Oct 15, 2013

@Ortuna you can push to padrino-start-accepts-handler-options

@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Oct 15, 2013

Contributor

Done @Ortuna, thanks! :)

Contributor

dariocravero commented Oct 15, 2013

Done @Ortuna, thanks! :)

ujifgc added a commit that referenced this pull request Oct 16, 2013

Merge pull request #1452 from padrino/padrino-start-accepts-handler-o…
…ptions

Allow padrino start to take handler specific options

@ujifgc ujifgc merged commit 3c80cac into master Oct 16, 2013

1 check failed

default The Travis CI build could not complete due to an error
Details

@ujifgc ujifgc deleted the padrino-start-accepts-handler-options branch Oct 16, 2013

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