Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for updating Lmod caches #175

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
69 changes: 69 additions & 0 deletions scripts/update_lmod_caches.sh
Original file line number Diff line number Diff line change
@@ -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 <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 gien stack)
bedroge marked this conversation as resolved.
Show resolved Hide resolved
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;
bedroge marked this conversation as resolved.
Show resolved Hide resolved
# - 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}" <<LMODRCEOF
propT = {
}
scDescriptT = {
{
["dir"] = "${DOT_LMOD}/cache",
["timestamp"] = "${DOT_LMOD}/cache/timestamp",
},
}
LMODRCEOF
fi

${update_lmod_system_cache_files=} -d ${DOT_LMOD}/cache -t ${DOT_LMOD}/cache/timestamp ${archdir}/modules/all
echo_green "Updated the Lmod cache for ${archdir}."
bedroge marked this conversation as resolved.
Show resolved Hide resolved
done
Loading