1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 if !File.owned?(Rails.root.join('tmp'))
6 Rails.logger.debug("reload_config: not owner of #{Rails.root}/tmp, skipping")
7 elsif ENV["ARVADOS_CONFIG"] == "none"
8 Rails.logger.debug("reload_config: no config in use, skipping")
11 lockfile = Rails.root.join('tmp', 'reload_config.lock')
12 File.open(lockfile, File::WRONLY|File::CREAT, 0600) do |f|
13 # Note we don't use LOCK_NB here. If we did, each time passenger
14 # kills the lock-holder process, we would be left with nobody
15 # checking for updates until passenger starts a new worker,
16 # which could be a long time.
17 Rails.logger.debug("reload_config: waiting for lock on #{lockfile}")
18 f.flock(File::LOCK_EX)
19 conffile = ENV['ARVADOS_CONFIG'] || "/etc/arvados/config.yml"
20 Rails.logger.info("reload_config: polling for updated mtime on #{conffile} with threshold #{Rails.configuration.SourceTimestamp}")
23 t = File.mtime(conffile)
24 if t.to_f > Rails.configuration.SourceTimestamp.to_f
25 restartfile = Rails.root.join('tmp', 'restart.txt')
27 Rails.logger.info("reload_config: mtime on #{conffile} changed to #{t}, touching #{restartfile} to #{touchtime}")
28 File.utime(touchtime, touchtime, restartfile)
29 # Even if passenger doesn't notice that we hit restart.txt
30 # and kill our process, there's no point waiting around to