20198: Run config-watcher thread in a worker process, not preloader. 20198-passenger-restart
authorTom Clegg <tom@curii.com>
Thu, 2 Mar 2023 23:41:21 +0000 (18:41 -0500)
committerTom Clegg <tom@curii.com>
Thu, 2 Mar 2023 23:41:21 +0000 (18:41 -0500)
See https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

apps/workbench/config/initializers/reload_config.rb
services/api/config/initializers/reload_config.rb

index 6c5632e055513f740e926960409ecb8fe0f88365..ec6db0c0e287a36dbd6c758696141bc1722e8e35 100644 (file)
@@ -6,11 +6,7 @@
 # services/api/config/initializers/reload_config.rb and update this
 # copy. Or find a more reasonable way to share the code.
 
-if !File.owned?(Rails.root.join('tmp'))
-  Rails.logger.debug("reload_config: not owner of #{Rails.root}/tmp, skipping")
-elsif ENV["ARVADOS_CONFIG"] == "none"
-  Rails.logger.debug("reload_config: no config in use, skipping")
-else
+def start_reload_thread
   Thread.new do
     lockfile = Rails.root.join('tmp', 'reload_config.lock')
     File.open(lockfile, File::WRONLY|File::CREAT, 0600) do |f|
@@ -68,3 +64,15 @@ else
     end
   end
 end
+
+if !File.owned?(Rails.root.join('tmp'))
+  Rails.logger.debug("reload_config: not owner of #{Rails.root}/tmp, skipping")
+elsif ENV["ARVADOS_CONFIG"] == "none"
+  Rails.logger.debug("reload_config: no config in use, skipping")
+elsif defined?(PhusionPassenger)
+  PhusionPassenger.on_event(:starting_worker_process) do |forked|
+    start_reload_thread
+  end
+else
+  start_reload_thread
+end
index bdc815099d4f484c56e7964bb718525a3e66c465..b54e3bcf87e764aec3508aec0ff5444cc7de9c37 100644 (file)
@@ -2,11 +2,10 @@
 #
 # SPDX-License-Identifier: AGPL-3.0
 
-if !File.owned?(Rails.root.join('tmp'))
-  Rails.logger.debug("reload_config: not owner of #{Rails.root}/tmp, skipping")
-elsif ENV["ARVADOS_CONFIG"] == "none"
-  Rails.logger.debug("reload_config: no config in use, skipping")
-else
+# When updating this, please make the same changes in
+# apps/workbench/config/initializers/reload_config.rb as well.
+
+def start_reload_thread
   Thread.new do
     lockfile = Rails.root.join('tmp', 'reload_config.lock')
     File.open(lockfile, File::WRONLY|File::CREAT, 0600) do |f|
@@ -64,3 +63,15 @@ else
     end
   end
 end
+
+if !File.owned?(Rails.root.join('tmp'))
+  Rails.logger.debug("reload_config: not owner of #{Rails.root}/tmp, skipping")
+elsif ENV["ARVADOS_CONFIG"] == "none"
+  Rails.logger.debug("reload_config: no config in use, skipping")
+elsif defined?(PhusionPassenger)
+  PhusionPassenger.on_event(:starting_worker_process) do |forked|
+    start_reload_thread
+  end
+else
+  start_reload_thread
+end