Skip to content

Commit

Permalink
touch cache, its link, md5 and id, resolves aces#1282
Browse files Browse the repository at this point in the history
  • Loading branch information
MontrealSergiy committed Dec 20, 2023
1 parent 4a3547e commit 5a80441
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
41 changes: 40 additions & 1 deletion Bourreau/lib/bourreau_system_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# CBRAIN Project
#
# Copyright (C) 2008-2012
# Copyright (C) 2008-2024
# The Royal Institution for the Advancement of Learning
# McGill University
#
Expand All @@ -21,6 +21,7 @@
#

require 'socket'
require 'fileutils'

class BourreauSystemChecks < CbrainChecker #:nodoc:

Expand Down Expand Up @@ -484,6 +485,44 @@ def self.a100_ensure_dp_cache_symlink_exists #:nodoc:



# touch to avoid deletion by cluster bimonthly sctratch cleanup : 1) DataProvider cache dir, 2) DP_Cache_Key.md5 3) DP_Cache_Rev.id
# 4) gridshare dir, and 5) DP_Cache symbolic link located in it
# gridshare and cache_dir are typically updated often, but we touch them just in the case
def self.a105_ensure_dp_cache_and_symlink_will_exists #:nodoc:

myself = RemoteResource.current_resource
cache_dir = myself.dp_cache_dir
dp_cache_id = File.join cache_dir, DataProvider::DP_CACHE_ID_FILE
dp_cache_md5 = File.join cache_dir, DataProvider::DP_CACHE_MD5_FILE
gridshare_dir = myself.cms_shared_dir
sym_path = File.join gridshare_dir, DataProvider::DP_CACHE_SYML

puts "C> Updating timestamp for cache folder as well as its symlink, MD5 and ID files"

begin
FileUtils.touch [gridshare_dir, cache_dir, dp_cache_id, dp_cache_md5], verbose: true, nocreate: true
# files still might be deleted if a bourreau is not rebooted for a long time
# some cluster can have policies countering touch abuse
# touch command may fail for many reasons, e.g. resource issues
# sometimes touch might fails even if timestamp update is successful
rescue => e
puts "C> Cache MD5 and ID files timestamp update FAILED: " + e.message
return
end

# update timestamp for a softlink (rather than the folder it points to)

if system "touch -h #{sym_path}"
puts "C> Timestamps are updated."
else
puts "C> Cache symlink timestamp update FAILED!!!"
puts "C> Try to recreate the symlink manually!" # older version of touch or unix do no support symlink updates
end
return if Time.now - File.lstat(sym_path).mtime > 1.day # fail only if symlink is seriously outdated
end



def self.a110_ensure_task_class_git_commits_cached

#----------------------------------------------------------------------------
Expand Down
30 changes: 29 additions & 1 deletion BrainPortal/lib/portal_system_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# CBRAIN Project
#
# Copyright (C) 2008-2012
# Copyright (C) 2008-2024
# The Royal Institution for the Advancement of Learning
# McGill University
#
Expand Down Expand Up @@ -203,5 +203,33 @@ def self.z010_ensure_we_have_a_ssh_agent_locker #:nodoc:
)
end


# touch to avoid deletion by cluster bimonthly sctratch cleanup :
# 1) DataProvider cache dir
# 2) DP_Cache_Key.md5
# 3) DP_Cache_Rev.id
# 4) cache_dir which is typically updated often, but we touch it just in the case
def self.z020_dp_cache_and_symlink_will_exists #:nodoc:

myself = RemoteResource.current_resource
cache_dir = myself.dp_cache_dir
dp_cache_id = File.join cache_dir, DataProvider::DP_CACHE_ID_FILE
dp_cache_md5 = File.join cache_dir, DataProvider::DP_CACHE_MD5_FILE

puts "C> Updating timestamp for cache folder as well as its symlink, MD5 and ID files"

begin
FileUtils.touch [cache_dir, dp_cache_id, dp_cache_md5], verbose: true, nocreate: true
# files still might be deleted if a bourreau is not rebooted for a long time
# some cluster can have policies countering touch abuse
# touch command may fail for many reasons, e.g. resource issues
# sometimes touch might fails even if timestamp update is successful
puts "C> Timestamps are updated."
rescue => e
puts "C> Timestamps update FAILED: " + e.message
return
end
end

end

0 comments on commit 5a80441

Please sign in to comment.