Skip to content

Commit

Permalink
Check puma config environment file on control_cli
Browse files Browse the repository at this point in the history
Fix #1445
  • Loading branch information
spk committed Aug 5, 2019
1 parent 6b13202 commit 49a9d07
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/puma/control_cli.rb
Expand Up @@ -22,6 +22,7 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@control_auth_token = nil
@config_file = nil
@command = nil
@environment = ENV['RACK_ENV'] || "development"

@argv = argv.dup
@stdout = stdout
Expand Down Expand Up @@ -59,6 +60,11 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@config_file = arg
end

o.on "-e", "--environment ENVIRONMENT",
"The environment to run the Rack app on (default development)" do |arg|
@environment = arg
end

o.on_tail("-H", "--help", "Show this message") do
@stdout.puts o
exit
Expand All @@ -76,8 +82,10 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@command = argv.shift

unless @config_file == '-'
if @config_file.nil? and File.exist?('config/puma.rb')
@config_file = 'config/puma.rb'
if @config_file.nil?
@config_file = %W(config/puma/#{@environment}.rb config/puma.rb).find do |f|
File.exist?(f)
end
end

if @config_file
Expand Down Expand Up @@ -258,6 +266,7 @@ def start
run_args += ["--control-url", @control_url] if @control_url
run_args += ["--control-token", @control_auth_token] if @control_auth_token
run_args += ["-C", @config_file] if @config_file
run_args += ["-e", @environment] if @environment

events = Puma::Events.new @stdout, @stderr

Expand Down
31 changes: 31 additions & 0 deletions test/test_pumactl.rb
Expand Up @@ -29,6 +29,37 @@ def test_config_file
assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
end

def test_environment
ENV.delete 'RACK_ENV' # remove from travis
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "development", control_cli.instance_variable_get("@environment")
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
assert_equal "test", control_cli.instance_variable_get("@environment")
end

def test_config_file_exist
ENV.delete 'RACK_ENV' # remove from travis
port = 6001
Dir.mktmpdir do |d|
Dir.chdir(d) do
FileUtils.mkdir("config")
File.open("config/puma.rb", "w") { |f| f << "port #{port}" }
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "config/puma.rb",
control_cli.instance_variable_get("@config_file")
end
end
Dir.mktmpdir do |d|
Dir.chdir(d) do
FileUtils.mkdir_p("config/puma")
File.open("config/puma/development.rb", "w") { |f| f << "port #{port}" }
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "config/puma/development.rb",
control_cli.instance_variable_get("@config_file")
end
end
end

def test_control_no_token
opts = [
"--config-file", "test/config/control_no_token.rb",
Expand Down

0 comments on commit 49a9d07

Please sign in to comment.