Skip to content

A platform for community discussion. Free, open, simple.

DEV: Improve auto-restart parent process detection logic (#13068)

David Taylorb6b27bc383ec
diff --git a/bin/unicorn b/bin/unicorn
index 106649c75f4..cc241696db7 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -87,6 +87,8 @@ end
# This is handy if you want to bind a key to restarting unicorn in dev
if dev_mode
+ $unicorn_dev_supervisor_pid = Process.pid # rubocop:disable Style/GlobalVars
+
restart = true
while restart
restart = false
diff --git a/config/initializers/000-development_reload_warnings.rb b/config/initializers/000-development_reload_warnings.rb
index bedc2c1c587..374bb7415f6 100644
--- a/config/initializers/000-development_reload_warnings.rb
+++ b/config/initializers/000-development_reload_warnings.rb
@@ -12,7 +12,8 @@ if Rails.env.development? && !Rails.configuration.cache_classes && Discourse.run
]
Listen.to(*paths, only: /\.rb$/) do |modified, added, removed|
- auto_restart = ENV["AUTO_RESTART"] != "0"
+ supervisor_pid = $unicorn_dev_supervisor_pid # rubocop:disable Style/GlobalVars
+ auto_restart = supervisor_pid && ENV["AUTO_RESTART"] != "0"
files = modified + added + removed
@@ -25,7 +26,7 @@ if Rails.env.development? && !Rails.configuration.cache_classes && Discourse.run
message = auto_restart ? "Restarting server..." : "Server restart required. Automate this by setting AUTO_RESTART=1."
STDERR.puts "[DEV]: Edited files which are not autoloaded. #{message}"
STDERR.puts not_autoloaded.map { |path| "- #{path}".indent(7) }.join("\n")
- Process.kill("USR2", Process.ppid) if auto_restart
+ Process.kill("USR2", supervisor_pid) if auto_restart
end
end.start
end