Skip to content

Commit 482330d

Browse files
hschnerafaelfranca
andauthored
Do not generate pidfile in production environments (rails#50644)
* Remove pidfile in production * Update changelog * Update activestorage/test/dummy/config/puma.rb Co-authored-by: Rafael Mendonça França <[email protected]> * Update template and other dummy files --------- Co-authored-by: Rafael Mendonça França <[email protected]>
1 parent 7051c48 commit 482330d

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

actionmailbox/test/dummy/config/puma.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
environment ENV.fetch("RAILS_ENV") { "development" }
2929

3030
# Specifies the `pidfile` that Puma will use.
31-
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
31+
if ENV["PIDFILE"]
32+
pidfile ENV["PIDFILE"]
33+
else
34+
pidfile "tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
35+
end
3236

3337
# Allow puma to be restarted by `bin/rails restart` command.
3438
plugin :tmp_restart

actiontext/test/dummy/config/puma.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
environment ENV.fetch("RAILS_ENV") { "development" }
2929

3030
# Specifies the `pidfile` that Puma will use.
31-
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
31+
if ENV["PIDFILE"]
32+
pidfile ENV["PIDFILE"]
33+
else
34+
pidfile "tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
35+
end
3236

3337
# Allow puma to be restarted by `bin/rails restart` command.
3438
plugin :tmp_restart

activestorage/test/dummy/config/puma.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
environment ENV.fetch("RAILS_ENV") { "development" }
2929

3030
# Specifies the `pidfile` that Puma will use.
31-
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
31+
if ENV["PIDFILE"]
32+
pidfile ENV["PIDFILE"]
33+
else
34+
pidfile tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
35+
end
3236

3337
# Allow puma to be restarted by `bin/rails restart` command.
3438
plugin :tmp_restart

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Disable `pidfile` generation in production environment.
2+
3+
*Hans Schnedlitz*
4+
15
* Set `config.action_view.annotate_rendered_view_with_filenames` to `true` in the
26
development environment.
37

railties/lib/rails/commands/server/server_command.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ServerCommand < Base # :nodoc:
114114
class_option :using, aliases: "-u", type: :string,
115115
desc: "Specify the Rack server used to run the application (thin/puma/webrick).", banner: :name
116116
class_option :pid, aliases: "-P", type: :string,
117-
desc: "Specify the PID file - defaults to #{DEFAULT_PIDFILE}."
117+
desc: "Specify the PID file. Defaults to #{DEFAULT_PIDFILE} in development."
118118
class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
119119
desc: "Specify whether to perform caching in development."
120120
class_option :restart, type: :boolean, default: nil, hide: true
@@ -243,11 +243,13 @@ def log_to_stdout?
243243
end
244244

245245
def pid
246-
File.expand_path(options[:pid] || ENV.fetch("PIDFILE", DEFAULT_PIDFILE))
246+
default_pidfile = environment == "development" ? DEFAULT_PIDFILE : nil
247+
pid = options[:pid] || ENV["PIDFILE"] || default_pidfile
248+
File.expand_path(pid) if pid
247249
end
248250

249251
def prepare_restart
250-
FileUtils.rm_f(pid) if options[:restart]
252+
FileUtils.rm_f(pid) if pid && options[:restart]
251253
end
252254

253255
def rack_server_suggestion(server)

railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ port ENV.fetch("PORT") { 3000 }
2929
environment ENV.fetch("RAILS_ENV") { "development" }
3030

3131
# Specifies the `pidfile` that Puma will use.
32-
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
32+
if ENV["PIDFILE"]
33+
pidfile ENV["PIDFILE"]
34+
else
35+
pidfile "tmp/pids/server.pid" if ENV.fetch("RAILS_ENV", "development") == "development"
36+
end
3337

3438
# Allow puma to be restarted by `bin/rails restart` command.
3539
plugin :tmp_restart

0 commit comments

Comments
 (0)