mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Remove config from CLI
Don't store @cli_options in Launcher (there are too many "options" hashes and their roles are confusing, let's make them more obvious, the arguments passed to cli_options are parsed and turned into @options).
This commit is contained in:
parent
ffae12c40f
commit
256e886a45
2 changed files with 64 additions and 121 deletions
|
@ -47,8 +47,6 @@ module Puma
|
|||
@status = nil
|
||||
@runner = nil
|
||||
|
||||
@config = nil
|
||||
|
||||
setup_options
|
||||
|
||||
begin
|
||||
|
@ -59,11 +57,6 @@ module Puma
|
|||
end
|
||||
|
||||
@launcher = Puma::Launcher.new(@cli_options, events: @events, argv: @argv)
|
||||
|
||||
@launcher.config = self.config
|
||||
|
||||
@launcher.setup(@options)
|
||||
|
||||
end
|
||||
|
||||
## BACKWARDS COMPAT FOR TESTS
|
||||
|
@ -118,10 +111,14 @@ module Puma
|
|||
end
|
||||
|
||||
# The Configuration object used.
|
||||
attr_reader :config
|
||||
def config
|
||||
@launcher.config
|
||||
end
|
||||
|
||||
# The Hash of options used to configure puma.
|
||||
attr_reader :options
|
||||
def options
|
||||
@launcher.options
|
||||
end
|
||||
|
||||
# The Events object used to output information.
|
||||
attr_reader :events
|
||||
|
@ -139,54 +136,10 @@ module Puma
|
|||
Puma.windows?
|
||||
end
|
||||
|
||||
<<<<<<< HEAD
|
||||
def env
|
||||
@options[:environment] || @cli_options[:environment] || ENV['RACK_ENV'] || 'development'
|
||||
@launcher.env
|
||||
end
|
||||
|
||||
def write_state
|
||||
write_pid
|
||||
|
||||
path = @options[:state]
|
||||
return unless path
|
||||
|
||||
state = { 'pid' => Process.pid }
|
||||
cfg = @config.dup
|
||||
|
||||
KEYS_NOT_TO_PERSIST_IN_STATE.each { |k| cfg.options.delete(k) }
|
||||
state['config'] = cfg
|
||||
|
||||
require 'yaml'
|
||||
File.open(path, 'w') { |f| f.write state.to_yaml }
|
||||
end
|
||||
|
||||
# If configured, write the pid of the current process out
|
||||
# to a file.
|
||||
#
|
||||
def write_pid
|
||||
path = @options[:pidfile]
|
||||
return unless path
|
||||
|
||||
File.open(path, 'w') { |f| f.puts Process.pid }
|
||||
cur = Process.pid
|
||||
at_exit do
|
||||
delete_pidfile if cur == Process.pid
|
||||
end
|
||||
end
|
||||
|
||||
def delete_pidfile
|
||||
path = @options[:pidfile]
|
||||
File.unlink(path) if path && File.exist?(path)
|
||||
end
|
||||
|
||||
def graceful_stop
|
||||
@runner.stop_blocked
|
||||
log "=== puma shutdown: #{Time.now} ==="
|
||||
log "- Goodbye!"
|
||||
end
|
||||
|
||||
=======
|
||||
>>>>>>> Initial Seperation of CLI and Server Launcher work
|
||||
def jruby_daemon_start
|
||||
@launcher.jruby_daemon_start
|
||||
end
|
||||
|
@ -233,7 +186,6 @@ module Puma
|
|||
|
||||
def setup_options
|
||||
@cli_options = {}
|
||||
@options = {}
|
||||
|
||||
@parser = OptionParser.new do |o|
|
||||
o.on "-b", "--bind URI", "URI to bind to (tcp://, unix://, ssl://)" do |arg|
|
||||
|
|
|
@ -2,18 +2,68 @@ require 'puma/binder'
|
|||
|
||||
module Puma
|
||||
class Launcher
|
||||
|
||||
def initialize(cli_options = {}, launcher_options = {})
|
||||
@cli_options = cli_options
|
||||
@runner = nil
|
||||
@events = launcher_options[:events] or raise "must provide :events key"
|
||||
@argv = launcher_options[:argv] || "puma"
|
||||
@original_argv = @argv.dup
|
||||
@config = nil
|
||||
|
||||
@binder = Binder.new(@events)
|
||||
@binder.import_from_env
|
||||
|
||||
# Final internal representation of options is stored here
|
||||
# cli_options will be parsed
|
||||
@options = {}
|
||||
generate_restart_data
|
||||
|
||||
@env = @options[:environment] || ENV['RACK_ENV'] || 'development'
|
||||
|
||||
if cli_options[:config_file] == '-'
|
||||
cli_options[:config_file] = nil
|
||||
else
|
||||
cli_options[:config_file] ||= %W(config/puma/#{@env}.rb config/puma.rb).find { |f| File.exist?(f) }
|
||||
end
|
||||
|
||||
@config = Puma::Configuration.new(cli_options)
|
||||
|
||||
# Advertise the Configuration
|
||||
Puma.cli_config = @config
|
||||
|
||||
@config.load
|
||||
|
||||
@options = @config.options
|
||||
|
||||
if clustered? && (jruby? || windows?)
|
||||
unsupported 'worker mode not supported on JRuby or Windows'
|
||||
end
|
||||
|
||||
if @options[:daemon] && windows?
|
||||
unsupported 'daemon mode not supported on Windows'
|
||||
end
|
||||
|
||||
dir = @options[:directory]
|
||||
Dir.chdir(dir) if dir
|
||||
|
||||
prune_bundler if prune_bundler?
|
||||
|
||||
@env = @options[:environment] if @options[:environment]
|
||||
set_rack_environment
|
||||
|
||||
if clustered?
|
||||
@events.formatter = Events::PidFormatter.new
|
||||
@options[:logger] = @events
|
||||
|
||||
@runner = Cluster.new(self)
|
||||
else
|
||||
@runner = Single.new(self)
|
||||
end
|
||||
|
||||
@status = :run
|
||||
end
|
||||
|
||||
attr_reader :binder, :events
|
||||
attr_reader :binder, :events, :config, :options
|
||||
|
||||
## THIS STUFF IS NEEDED FOR RUNNER
|
||||
|
||||
|
@ -23,10 +73,6 @@ module Puma
|
|||
@events.log str
|
||||
end
|
||||
|
||||
def config
|
||||
@config
|
||||
end
|
||||
|
||||
def stats
|
||||
@runner.stats
|
||||
end
|
||||
|
@ -93,33 +139,6 @@ module Puma
|
|||
attr_accessor :options, :binder, :config
|
||||
## THIS STUFF IS NEEDED FOR RUNNER
|
||||
|
||||
|
||||
def setup(options)
|
||||
@options = options
|
||||
generate_restart_data
|
||||
|
||||
parse_options
|
||||
|
||||
dir = @options[:directory]
|
||||
Dir.chdir(dir) if dir
|
||||
|
||||
prune_bundler if prune_bundler?
|
||||
|
||||
set_rack_environment
|
||||
|
||||
if clustered?
|
||||
@events.formatter = Events::PidFormatter.new
|
||||
@options[:logger] = @events
|
||||
|
||||
@runner = Cluster.new(self)
|
||||
else
|
||||
@runner = Single.new(self)
|
||||
end
|
||||
|
||||
@status = :run
|
||||
end
|
||||
|
||||
|
||||
attr_accessor :runner
|
||||
|
||||
def stop
|
||||
|
@ -258,40 +277,15 @@ module Puma
|
|||
|
||||
|
||||
private
|
||||
def parse_options
|
||||
# backwards compat with CLI (private) interface
|
||||
end
|
||||
|
||||
def unsupported(str)
|
||||
@events.error(str)
|
||||
raise UnsupportedOption
|
||||
end
|
||||
|
||||
def parse_options
|
||||
find_config
|
||||
|
||||
@config = Puma::Configuration.new @cli_options
|
||||
|
||||
# Advertise the Configuration
|
||||
Puma.cli_config = @config
|
||||
|
||||
@config.load
|
||||
|
||||
@options = @config.options
|
||||
|
||||
if clustered? && (jruby? || windows?)
|
||||
unsupported 'worker mode not supported on JRuby or Windows'
|
||||
end
|
||||
|
||||
if @options[:daemon] && windows?
|
||||
unsupported 'daemon mode not supported on Windows'
|
||||
end
|
||||
end
|
||||
|
||||
def find_config
|
||||
if @cli_options[:config_file] == '-'
|
||||
@cli_options[:config_file] = nil
|
||||
else
|
||||
@cli_options[:config_file] ||= %W(config/puma/#{env}.rb config/puma.rb).find { |f| File.exist?(f) }
|
||||
end
|
||||
end
|
||||
|
||||
def graceful_stop
|
||||
@runner.stop_blocked
|
||||
log "=== puma shutdown: #{Time.now} ==="
|
||||
|
@ -314,10 +308,7 @@ module Puma
|
|||
end
|
||||
|
||||
def env
|
||||
@options[:environment] ||
|
||||
@cli_options[:environment] ||
|
||||
ENV['RACK_ENV'] ||
|
||||
'development'
|
||||
@env
|
||||
end
|
||||
|
||||
def prune_bundler?
|
||||
|
|
Loading…
Reference in a new issue