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")
9 lockfile = Rails.root.join('tmp', 'reload_config.lock')
10 File.open(lockfile, File::WRONLY|File::CREAT, 0600) do |f|
11 # Note we don't use LOCK_NB here. If we did, each time passenger
12 # kills the lock-holder process, we would be left with nobody
13 # checking for updates until passenger starts a new worker,
14 # which could be a long time.
15 Rails.logger.debug("reload_config: waiting for lock on #{lockfile}")
16 f.flock(File::LOCK_EX)
17 conffile = ENV['ARVADOS_CONFIG'] || "/etc/arvados/config.yml"
18 Rails.logger.info("reload_config: polling for updated mtime on #{conffile} with threshold #{Rails.configuration.SourceTimestamp}")
21 t = File.mtime(conffile)
22 if t.to_f > Rails.configuration.SourceTimestamp.to_f
23 restartfile = Rails.root.join('tmp', 'restart.txt')
25 Rails.logger.info("reload_config: mtime on #{conffile} changed to #{t}, touching #{restartfile} to #{touchtime}")
26 File.utime(touchtime, touchtime, restartfile)
27 # Even if passenger doesn't notice that we hit restart.txt
28 # and kill our process, there's no point waiting around to