From f112648c02024dd54d9fcaffacfeab5a9debecfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bob=20Dr=C3=B6ge?= Date: Sat, 27 Jan 2024 22:56:44 +0100 Subject: [PATCH 1/6] script for updating all Lmod caches --- scripts/update_lmod_caches.sh | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 scripts/update_lmod_caches.sh diff --git a/scripts/update_lmod_caches.sh b/scripts/update_lmod_caches.sh new file mode 100755 index 00000000..63216ac6 --- /dev/null +++ b/scripts/update_lmod_caches.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +function echo_green() { + echo -e "\e[32m$1\e[0m" +} + +function echo_red() { + echo -e "\e[31m$1\e[0m" +} + +function error() { + echo_red "ERROR: $1" >&2 + exit 1 +} + +# Check if a stack base dir has been specified +if [ "$#" -ne 1 ]; then + error "usage: $0 " +fi + +stack_base_dir="$1" + +# Check if the given stack base dir exists +if [ ! -d ${stack_base_dir} ] +then + error "${stack_base_dir} does not point to an existing directory!" +fi + +# Check if Lmod's cache update script can be found at the expected location (in the compatibility layer of the gien stack) +update_lmod_system_cache_files="${stack_base_dir}/compat/linux/$(uname -m)/usr/share/Lmod/libexec/update_lmod_system_cache_files" +if [ ! -f ${update_lmod_system_cache_files} ] +then + error "expected to find Lmod's cache update script at ${update_lmod_system_cache_files}, but it doesn't exist." +fi + +# Find all subtrees of supported CPU targets by looking for "modules" directories, and taking their parent directory +architectures=$(find ${stack_base_dir}/software/ -maxdepth 5 -type d -name modules -exec dirname {} \;) + +# For every subtree: +# - create an .lmod directory; +# - add an lmodrc.lua file that defines the location of the cache; +# - create or update the cache. +for archdir in ${architectures} +do + DOT_LMOD="${archdir}/.lmod" + LMOD_RC="${archdir}/.lmod/lmodrc.lua" + + if [ ! -d "${DOT_LMOD}" ] + then + mkdir -p "${DOT_LMOD}/cache" + fi + + if [ ! -f "${LMOD_RC}" ] + then + cat > "${LMOD_RC}" < Date: Sat, 27 Jan 2024 23:34:17 +0100 Subject: [PATCH 2/6] call the cache update script after ingesting a software tarball --- scripts/ingest-tarball.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/ingest-tarball.sh b/scripts/ingest-tarball.sh index d71ff733..9b008199 100755 --- a/scripts/ingest-tarball.sh +++ b/scripts/ingest-tarball.sh @@ -168,6 +168,23 @@ function check_arch() { fi } +function update_lmod_caches() { + # Update the Lmod caches for the stacks of all supported CPUs + script_dir=$(dirname $(realpath $BASH_SOURCE)) + update_caches_script=${script_dir}/update_lmod_caches.sh + if [ ! -f ${update_caches_script} ] + then + error "cannot find the script for updating the Lmod caches; it should be placed in the same directory as the ingestion script!" + fi + if [ ! -x ${update_caches_script} ] + then + error "the script for updating the Lmod caches (${update_caches_script}) does not have execute permissions!" + fi + cvmfs_server transaction "${repo}" + ${update_caches_script} /cvmfs/${repo}/${basedir}/${version} + cvmfs_server publish -m "update Lmod caches after ingesting ${tar_file_basename}" "${repo}" +} + function ingest_init_tarball() { # Handle the ingestion of tarballs containing init scripts cvmfs_ingest_tarball @@ -183,6 +200,7 @@ function ingest_software_tarball() { check_arch check_os cvmfs_ingest_tarball + update_lmod_caches } function ingest_compat_tarball() { From 09aa76b94207db9b7117fc614fb553ad7601375b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bob=20Dr=C3=B6ge?= Date: Mon, 29 Jan 2024 11:05:36 +0100 Subject: [PATCH 3/6] remove code for creating lmod_rc --- scripts/update_lmod_caches.sh | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/scripts/update_lmod_caches.sh b/scripts/update_lmod_caches.sh index 63216ac6..52aa128a 100755 --- a/scripts/update_lmod_caches.sh +++ b/scripts/update_lmod_caches.sh @@ -36,34 +36,10 @@ fi # Find all subtrees of supported CPU targets by looking for "modules" directories, and taking their parent directory architectures=$(find ${stack_base_dir}/software/ -maxdepth 5 -type d -name modules -exec dirname {} \;) -# For every subtree: -# - create an .lmod directory; -# - add an lmodrc.lua file that defines the location of the cache; -# - create or update the cache. +# Create/update the Lmod cache for all architectures for archdir in ${architectures} do - DOT_LMOD="${archdir}/.lmod" - LMOD_RC="${archdir}/.lmod/lmodrc.lua" - - if [ ! -d "${DOT_LMOD}" ] - then - mkdir -p "${DOT_LMOD}/cache" - fi - - if [ ! -f "${LMOD_RC}" ] - then - cat > "${LMOD_RC}" < Date: Tue, 26 Mar 2024 10:05:22 +0100 Subject: [PATCH 4/6] fix typo Co-authored-by: Kenneth Hoste --- scripts/update_lmod_caches.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_lmod_caches.sh b/scripts/update_lmod_caches.sh index 52aa128a..96479f07 100755 --- a/scripts/update_lmod_caches.sh +++ b/scripts/update_lmod_caches.sh @@ -26,7 +26,7 @@ then error "${stack_base_dir} does not point to an existing directory!" fi -# Check if Lmod's cache update script can be found at the expected location (in the compatibility layer of the gien stack) +# Check if Lmod's cache update script can be found at the expected location (in the compatibility layer of the given stack) update_lmod_system_cache_files="${stack_base_dir}/compat/linux/$(uname -m)/usr/share/Lmod/libexec/update_lmod_system_cache_files" if [ ! -f ${update_lmod_system_cache_files} ] then From f01b66b5f4e2d53e2260a6d34cffee1b35d85243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bob=20Dr=C3=B6ge?= Date: Tue, 26 Mar 2024 10:05:50 +0100 Subject: [PATCH 5/6] fix typo in variable name Co-authored-by: Kenneth Hoste --- scripts/update_lmod_caches.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_lmod_caches.sh b/scripts/update_lmod_caches.sh index 96479f07..035622be 100755 --- a/scripts/update_lmod_caches.sh +++ b/scripts/update_lmod_caches.sh @@ -40,6 +40,6 @@ architectures=$(find ${stack_base_dir}/software/ -maxdepth 5 -type d -name modul for archdir in ${architectures} do lmod_cache_dir="${archdir}/.lmod/cache" - ${update_lmod_system_cache_files=} -d ${lmod_cache_dir} -t ${lmod_cache_dir}/timestamp ${archdir}/modules/all + ${update_lmod_system_cache_files} -d ${lmod_cache_dir} -t ${lmod_cache_dir}/timestamp ${archdir}/modules/all echo_green "Updated the Lmod cache for ${archdir}." done From 3a391120ad9f53bdbeb19ae7697e75f179fdd4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bob=20Dr=C3=B6ge?= Date: Tue, 26 Mar 2024 10:06:46 +0100 Subject: [PATCH 6/6] add exit code check and add some debugging info Co-authored-by: Kenneth Hoste --- scripts/update_lmod_caches.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/update_lmod_caches.sh b/scripts/update_lmod_caches.sh index 035622be..f1765f0c 100755 --- a/scripts/update_lmod_caches.sh +++ b/scripts/update_lmod_caches.sh @@ -41,5 +41,12 @@ for archdir in ${architectures} do lmod_cache_dir="${archdir}/.lmod/cache" ${update_lmod_system_cache_files} -d ${lmod_cache_dir} -t ${lmod_cache_dir}/timestamp ${archdir}/modules/all - echo_green "Updated the Lmod cache for ${archdir}." + exit_code=$? + if [[ ${exit_code} -eq 0 ]]; then + echo_green "Updated the Lmod cache for ${archdir}." + ls -lrt ${lmod_cache_dir} + else + echo_red "Updating the Lmod cache failed for ${archdir}." + exit ${exit_code} + fi done