Skip to content
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

Pumactl broken environment option #2023

Closed
AlexWayfer opened this issue Oct 10, 2019 · 6 comments · Fixed by #2035
Closed

Pumactl broken environment option #2023

AlexWayfer opened this issue Oct 10, 2019 · 6 comments · Fixed by #2035

Comments

@AlexWayfer
Copy link
Contributor

Describe the bug

Our production is in development mode now. environment method in config/puma.rb is broken (after #1885, I guess).

Puma config:

# frozen_string_literal: true

environment 'production'

app do |env|
  [200, {}, ["embedded app"]]
end

To Reproduce

# Gemfile

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'puma', '< 4.2'
> bundle exec pumactl start -F puma_config.rb
Puma starting in single mode...
* Version 4.1.1 (ruby 2.6.5-p114), codename: Fourth and One
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop
# Gemfile

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'puma', '>= 4.2'
> bundle exec pumactl start -F puma_config.rb
Puma starting in single mode...
* Version 4.2.0 (ruby 2.6.5-p114), codename: Distant Airhorns
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop

Expected behavior

production in production, not development after any value for environment method.

Desktop (please complete the following information):

  • OS: Linux
  • Puma Version ≥ 4.2
@dentarg
Copy link
Member

dentarg commented Oct 10, 2019

This is true also on the latest version, Puma 4.2.1

$ cat production_config.rb
environment "production"
workers 1
app do |env|
  [200, {}, ["embedded app"]]
end

$ bundle exec pumactl start -F production_config.rb
[7752] Puma starting in cluster mode...
[7752] * Version 4.2.1 (ruby 2.6.5-p114), codename: Distant Airhorns
[7752] * Min threads: 0, max threads: 16
[7752] * Environment: development
[7752] * Process workers: 1
[7752] * Phased restart available
[7752] * Listening on tcp://0.0.0.0:9292
[7752] Use Ctrl-C to stop
[7752] - Worker 0 (pid: 7753) booted, phase: 0
^C[7752] - Gracefully shutting down workers...
[7752] === puma shutdown: 2019-10-10 22:50:05 +0200 ===
[7752] - Goodbye!

Note that puma still does the right thing:

$ bundle exec puma -C production_config.rb
[7669] Puma starting in cluster mode...
[7669] * Version 4.2.1 (ruby 2.6.5-p114), codename: Distant Airhorns
[7669] * Min threads: 0, max threads: 16
[7669] * Environment: production
[7669] * Process workers: 1
[7669] * Phased restart available
[7669] * Listening on tcp://0.0.0.0:9292
[7669] Use Ctrl-C to stop
[7669] - Worker 0 (pid: 7670) booted, phase: 0
^C[7669] - Gracefully shutting down workers...
[7669] === puma shutdown: 2019-10-10 22:49:20 +0200 ===
[7669] - Goodbye!

I'm not very familiar with these things, but it looks to me that pumactl is a wrapper around puma (via Puma::CLI)

run_args += ["-C", @config_file] if @config_file
run_args += ["-e", @environment] if @environment
events = Puma::Events.new @stdout, @stderr
# replace $0 because puma use it to generate restart command
puma_cmd = $0.gsub(/pumactl$/, 'puma')
$0 = puma_cmd if File.exist?(puma_cmd)
cli = Puma::CLI.new run_args, events
cli.run

It actually makes sense that the environment value from pumactl passed on to puma is the preferred one over what's in the config file. That's usually the logical way to arrange it. You use the command line to override your config file.

Maybe #1885 shouldn't have added the -e, --environment ENVIRONMENT flag to pumactl. I take it that the author wanted to use RACK_ENV to figure out which config file to use, which to me hasn't much to do with adding the flag.

@dentarg
Copy link
Member

dentarg commented Oct 10, 2019

Maybe #1885 shouldn't have added the -e, --environment ENVIRONMENT flag to pumactl. I take it that the author wanted to use RACK_ENV to figure out which config file to use, which to me hasn't much to do with adding the flag.

It is the default value that is the problem

@environment = ENV['RACK_ENV'] || "development"

If -e (with pumactl) isn't used or RACK_ENV isn't set, sure, maybe look for a development config file, but don't pass -e development to puma (Puma::CLI).

@nateberkopec nateberkopec changed the title Broken environment option Pumactl broken environment option Oct 10, 2019
@AlexWayfer
Copy link
Contributor Author

If -e (with pumactl) isn't used or RACK_ENV isn't set, sure, maybe look for a development config file, but don't pass -e development to puma (Puma::CLI).

Also, ENV['RACK_ENV'] = 'production' in config.rb for pumactl doesn't work.

@AndrewSpeed
Copy link
Contributor

👋 I'm happy to have a go at fixing this

Are the following scenarios the behaviour we want to see?

-e RACK_ENV environment passed to Puma::CLI config files to look for
production nil production config/puma/production.rb, config/puma.rb
nil production production config/puma/production.rb, config/puma.rb
development production development config/puma/development.rb, config/puma.rb
nil nil nil config/puma/development.rb, config/puma.rb

@AlexWayfer
Copy link
Contributor Author

Are the following scenarios the behaviour we want to see?

Yes, looks good to me. Thank you. I can try to fix it too, so please write if you'll have problems.

@AlexWayfer
Copy link
Contributor Author

Thank you! I'll wait for a new release.

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

Successfully merging a pull request may close this issue.

4 participants