18794: Make "touch restart.txt" recipe work when owned by root.
authorTom Clegg <tom@curii.com>
Thu, 5 May 2022 21:42:46 +0000 (17:42 -0400)
committerTom Clegg <tom@curii.com>
Thu, 5 May 2022 21:42:46 +0000 (17:42 -0400)
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@curii.com>

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

index 259f54732ca8211fade0db2d8a5b3a52b40198ee..58949c5e935950ed06c0c92dc1f1c10271f4e3b0 100644 (file)
@@ -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
index 65f02e07a4e8bf942657358c1fd9538c7b7813af..1582855bfb29203a511546a3b7ec505dfee4658f 100644 (file)
@@ -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