Merge branch '20846-ubuntu2204'
[arvados.git] / services / api / config / initializers / reload_config.rb
index 1582855bfb29203a511546a3b7ec505dfee4658f..f6ef8af963b434bc53f573c107c50aa56b29c2d4 100644 (file)
@@ -2,11 +2,7 @@
 #
 # 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
+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|
@@ -30,18 +26,18 @@ else
         # precision cannot represent multiple updates per second.
         if t.to_f != t_lastload.to_f || Time.now.to_f - t.to_f < 5
           Open3.popen2("arvados-server", "config-dump", "-skip-legacy") do |stdin, stdout, status_thread|
-            confs = YAML.load(stdout, deserialize_symbols: false)
+            confs = YAML.safe_load(stdout)
             hash = confs["SourceSHA256"]
           rescue => e
             Rails.logger.info("reload_config: config file updated but could not be loaded: #{e}")
             t_lastload = t
-            continue
+            next
           end
           if hash == hash_lastload
             # If we reloaded a new or updated file, but the content is
             # identical, keep polling instead of restarting.
             t_lastload = t
-            continue
+            next
           end
 
           restartfile = Rails.root.join('tmp', 'restart.txt')
@@ -64,3 +60,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