Do not generate pidfile in production environments (#50644)

* Remove pidfile in production

* Update changelog

* Update activestorage/test/dummy/config/puma.rb

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

* Update template and other dummy files

---------

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
This commit is contained in:
Hans Schnedlitz 2024-01-08 20:47:25 +01:00 committed by GitHub
parent 7051c482e9
commit 482330d156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 7 deletions

View File

@ -28,7 +28,11 @@ port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
if ENV["PIDFILE"]
pidfile ENV["PIDFILE"]
else
pidfile "tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
end
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

View File

@ -28,7 +28,11 @@ port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
if ENV["PIDFILE"]
pidfile ENV["PIDFILE"]
else
pidfile "tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
end
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

View File

@ -28,7 +28,11 @@ port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
if ENV["PIDFILE"]
pidfile ENV["PIDFILE"]
else
pidfile tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
end
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

View File

@ -1,3 +1,7 @@
* Disable `pidfile` generation in production environment.
*Hans Schnedlitz*
* Set `config.action_view.annotate_rendered_view_with_filenames` to `true` in the
development environment.

View File

@ -114,7 +114,7 @@ module Rails
class_option :using, aliases: "-u", type: :string,
desc: "Specify the Rack server used to run the application (thin/puma/webrick).", banner: :name
class_option :pid, aliases: "-P", type: :string,
desc: "Specify the PID file - defaults to #{DEFAULT_PIDFILE}."
desc: "Specify the PID file. Defaults to #{DEFAULT_PIDFILE} in development."
class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
desc: "Specify whether to perform caching in development."
class_option :restart, type: :boolean, default: nil, hide: true
@ -243,11 +243,13 @@ module Rails
end
def pid
File.expand_path(options[:pid] || ENV.fetch("PIDFILE", DEFAULT_PIDFILE))
default_pidfile = environment == "development" ? DEFAULT_PIDFILE : nil
pid = options[:pid] || ENV["PIDFILE"] || default_pidfile
File.expand_path(pid) if pid
end
def prepare_restart
FileUtils.rm_f(pid) if options[:restart]
FileUtils.rm_f(pid) if pid && options[:restart]
end
def rack_server_suggestion(server)

View File

@ -29,7 +29,11 @@ port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
if ENV["PIDFILE"]
pidfile ENV["PIDFILE"]
else
pidfile "tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
end
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart