mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 05:47:31 +08:00
DEV: Improve auto-restart parent process detection logic (#13068)
The auto restart logic was sending a USR2 to the parent process without checking what the parent process actually was. In some situations, it might not be the `bin/unicorn` supervisor. This commit switches to use a global variable for the supervisor PID. This will be much less prone to unexpected behavior.
This commit is contained in:
parent
32d6d8308c
commit
b6b27bc383
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user