diff --git a/History.md b/History.md index 0e11b546f2..c47300cd2a 100644 --- a/History.md +++ b/History.md @@ -2,6 +2,7 @@ * Features * Add pumactl `thread-backtraces` command to print thread backtraces (#2053) + * Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022) * Bugfixes * Your bugfix goes here (#Github Number) @@ -12,8 +13,10 @@ * Features * Strip whitespace at end of HTTP headers (#2010) * Optimize HTTP parser for JRuby (#2012) + * Add SSL support for the control app (#2046) * Add SSL support for the control app and cli (#2046, #2052) + * Bugfixes * Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564) * Fix pumactl defaulting puma to development if an environment was not specified (#2035) diff --git a/README.md b/README.md index 78d1281945..73bea0298b 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag: $ puma -C /path/to/config ``` -If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` environment variable, Puma looks for configuration at `config/puma/.rb`. +If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma looks for configuration at `config/puma/.rb`. If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag: @@ -275,7 +275,7 @@ reliability in production environments: ## Community Plugins -* [puma-heroku](https://github.com/evanphx/puma-heroku) — default Puma configuration for running on Heroku +* [puma-heroku](https://github.com/puma/puma-heroku) — default Puma configuration for running on Heroku * [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus * [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd * [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 6034520a1f..5c40adf09d 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -182,7 +182,7 @@ def puma_default_options :worker_shutdown_timeout => DefaultWorkerShutdownTimeout, :remote_address => :socket, :tag => method(:infer_tag), - :environment => -> { ENV['RACK_ENV'] || "development" }, + :environment => -> { ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" }, :rackup => DefaultRackup, :logger => STDOUT, :persistent_timeout => Const::PERSISTENT_TIMEOUT, diff --git a/lib/puma/control_cli.rb b/lib/puma/control_cli.rb index 53cbd978d4..2897f63063 100644 --- a/lib/puma/control_cli.rb +++ b/lib/puma/control_cli.rb @@ -23,7 +23,7 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR) @control_auth_token = nil @config_file = nil @command = nil - @environment = ENV['RACK_ENV'] + @environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] @argv = argv.dup @stdout = stdout diff --git a/test/test_cli.rb b/test/test_cli.rb index e2e55f7b2f..5e75cb2eb0 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -384,11 +384,22 @@ def test_extra_runtime_dependencies assert_equal %w[a b], extra_dependencies end - def test_environment + def test_environment_rack_env ENV.delete 'RACK_ENV' Puma::CLI.new ["--environment", @environment] - assert_equal ENV['RACK_ENV'], @environment + assert_equal @environment, ENV['RACK_ENV'] + end + + def test_environment_rails_env + ENV.delete 'RACK_ENV' + ENV['RAILS_ENV'] = @environment + + Puma::CLI.new [] + + assert_equal @environment, ENV['RACK_ENV'] + + ENV.delete 'RAILS_ENV' end end diff --git a/test/test_config.rb b/test/test_config.rb index 870d69170d..d3d87d0902 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -230,6 +230,15 @@ def test_config_files_with_rack_env end end + def test_config_files_with_rails_env + with_env('RAILS_ENV' => 'fake-env', 'RACK_ENV' => nil) do + conf = Puma::Configuration.new do + end + + assert_equal ['config/puma/fake-env.rb'], conf.config_files + end + end + def test_config_files_with_specified_environment conf = Puma::Configuration.new do end diff --git a/test/test_pumactl.rb b/test/test_pumactl.rb index 20e56e0ebc..0e9ea1e49f 100644 --- a/test/test_pumactl.rb +++ b/test/test_pumactl.rb @@ -53,7 +53,7 @@ def test_rack_env_without_environment end def test_environment_without_rack_env - with_env("RACK_ENV" => nil) do + with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do control_cli = Puma::ControlCLI.new ["halt"] assert_nil control_cli.instance_variable_get("@environment") @@ -95,7 +95,7 @@ def test_default_config_file_exist puma_config_file = "config/puma.rb" development_config_file = "config/puma/development.rb" - with_env("RACK_ENV" => nil) do + with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do with_config_file(puma_config_file, port) do control_cli = Puma::ControlCLI.new ["halt"] assert_equal puma_config_file, control_cli.instance_variable_get("@config_file")