[ARVADOS] updated: 2.1.0-2423-g00542ded6
Git user
git at public.arvados.org
Thu May 5 21:45:03 UTC 2022
Summary of changes:
.../api => apps/workbench}/config/initializers/reload_config.rb | 7 +++++++
services/api/config/initializers/reload_config.rb | 3 +++
2 files changed, 10 insertions(+)
copy {services/api => apps/workbench}/config/initializers/reload_config.rb (88%)
via 00542ded608212e8245429001f1a0a0a736f2e71 (commit)
via eaaec81f7cd6c26b3496d800f8e1827ab7a6445c (commit)
from fc4f842bfa62b4ab5e6a9d233eb88cc78758f376 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 00542ded608212e8245429001f1a0a0a736f2e71
Author: Tom Clegg <tom at curii.com>
Date: Thu May 5 17:42:46 2022 -0400
18794: Make "touch restart.txt" recipe work when owned by root.
If root has done "touch {tmp}/restart.txt", then the www-data user
cannot utime() or write() the existing file, but can remove it and
create a new one.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/apps/workbench/config/initializers/reload_config.rb b/apps/workbench/config/initializers/reload_config.rb
index 259f54732..58949c5e9 100644
--- a/apps/workbench/config/initializers/reload_config.rb
+++ b/apps/workbench/config/initializers/reload_config.rb
@@ -54,6 +54,9 @@ else
begin
File.utime(touchtime, touchtime, restartfile)
rescue
+ # remove + re-create works even if the existing file is
+ # owned by root, provided the tempdir is writable.
+ File.unlink(restartfile) rescue nil
File.open(restartfile, 'w') {}
end
# Even if passenger doesn't notice that we hit restart.txt
diff --git a/services/api/config/initializers/reload_config.rb b/services/api/config/initializers/reload_config.rb
index 65f02e07a..1582855bf 100644
--- a/services/api/config/initializers/reload_config.rb
+++ b/services/api/config/initializers/reload_config.rb
@@ -50,6 +50,9 @@ else
begin
File.utime(touchtime, touchtime, restartfile)
rescue
+ # remove + re-create works even if the existing file is
+ # owned by root, provided the tempdir is writable.
+ File.unlink(restartfile) rescue nil
File.open(restartfile, 'w') {}
end
# Even if passenger doesn't notice that we hit restart.txt
commit eaaec81f7cd6c26b3496d800f8e1827ab7a6445c
Author: Tom Clegg <tom at curii.com>
Date: Thu May 5 17:21:33 2022 -0400
18794: Auto-reload workbench1 config, too.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/apps/workbench/config/initializers/reload_config.rb b/apps/workbench/config/initializers/reload_config.rb
new file mode 100644
index 000000000..259f54732
--- /dev/null
+++ b/apps/workbench/config/initializers/reload_config.rb
@@ -0,0 +1,67 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+# Please don't edit this version. Instead, edit
+# 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
+ Thread.new do
+ lockfile = Rails.root.join('tmp', 'reload_config.lock')
+ File.open(lockfile, File::WRONLY|File::CREAT, 0600) do |f|
+ # Note we don't use LOCK_NB here. If we did, each time passenger
+ # kills the lock-holder process, we would be left with nobody
+ # checking for updates until passenger starts a new worker,
+ # which could be a long time.
+ Rails.logger.debug("reload_config: waiting for lock on #{lockfile}")
+ f.flock(File::LOCK_EX)
+
+ t_lastload = Rails.configuration.SourceTimestamp
+ hash_lastload = Rails.configuration.SourceSHA256
+ conffile = ENV['ARVADOS_CONFIG'] || "/etc/arvados/config.yml"
+ Rails.logger.info("reload_config: polling for updated mtime on #{conffile} with threshold #{t_lastload}")
+ while true
+ sleep 1
+ t = File.mtime(conffile)
+ # If the file is newer than 5s, re-read it even if the
+ # timestamp matches the previously loaded file. This enables
+ # us to detect changes even if the filesystem's timestamp
+ # 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)
+ hash = confs["SourceSHA256"]
+ rescue => e
+ Rails.logger.info("reload_config: config file updated but could not be loaded: #{e}")
+ t_lastload = t
+ continue
+ 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
+ end
+
+ restartfile = Rails.root.join('tmp', 'restart.txt')
+ touchtime = Time.now
+ Rails.logger.info("reload_config: mtime on #{conffile} changed to #{t}, touching #{restartfile} to #{touchtime}")
+ begin
+ File.utime(touchtime, touchtime, restartfile)
+ rescue
+ File.open(restartfile, 'w') {}
+ end
+ # Even if passenger doesn't notice that we hit restart.txt
+ # and kill our process, there's no point waiting around to
+ # hit it again.
+ break
+ end
+ end
+ end
+ end
+end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list