Skip to content

Commit

Permalink
Merge pull request #175 from bedroge/update_lmod_cache_script
Browse files Browse the repository at this point in the history
Add script for updating Lmod caches
  • Loading branch information
boegel authored Mar 26, 2024
2 parents dd493cc + 3a39112 commit 8675554
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/ingest-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -183,6 +200,7 @@ function ingest_software_tarball() {
check_arch
check_os
cvmfs_ingest_tarball
update_lmod_caches
}

function ingest_compat_tarball() {
Expand Down
52 changes: 52 additions & 0 deletions scripts/update_lmod_caches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/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 <path to main directory of an EESSI stack>"
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 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
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 {} \;)

# Create/update the Lmod cache for all architectures
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
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

0 comments on commit 8675554

Please sign in to comment.