Skip to content

Commit 8675554

Browse files
authored
Merge pull request #175 from bedroge/update_lmod_cache_script
Add script for updating Lmod caches
2 parents dd493cc + 3a39112 commit 8675554

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

scripts/ingest-tarball.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ function check_arch() {
168168
fi
169169
}
170170

171+
function update_lmod_caches() {
172+
# Update the Lmod caches for the stacks of all supported CPUs
173+
script_dir=$(dirname $(realpath $BASH_SOURCE))
174+
update_caches_script=${script_dir}/update_lmod_caches.sh
175+
if [ ! -f ${update_caches_script} ]
176+
then
177+
error "cannot find the script for updating the Lmod caches; it should be placed in the same directory as the ingestion script!"
178+
fi
179+
if [ ! -x ${update_caches_script} ]
180+
then
181+
error "the script for updating the Lmod caches (${update_caches_script}) does not have execute permissions!"
182+
fi
183+
cvmfs_server transaction "${repo}"
184+
${update_caches_script} /cvmfs/${repo}/${basedir}/${version}
185+
cvmfs_server publish -m "update Lmod caches after ingesting ${tar_file_basename}" "${repo}"
186+
}
187+
171188
function ingest_init_tarball() {
172189
# Handle the ingestion of tarballs containing init scripts
173190
cvmfs_ingest_tarball
@@ -183,6 +200,7 @@ function ingest_software_tarball() {
183200
check_arch
184201
check_os
185202
cvmfs_ingest_tarball
203+
update_lmod_caches
186204
}
187205

188206
function ingest_compat_tarball() {

scripts/update_lmod_caches.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
function echo_green() {
4+
echo -e "\e[32m$1\e[0m"
5+
}
6+
7+
function echo_red() {
8+
echo -e "\e[31m$1\e[0m"
9+
}
10+
11+
function error() {
12+
echo_red "ERROR: $1" >&2
13+
exit 1
14+
}
15+
16+
# Check if a stack base dir has been specified
17+
if [ "$#" -ne 1 ]; then
18+
error "usage: $0 <path to main directory of an EESSI stack>"
19+
fi
20+
21+
stack_base_dir="$1"
22+
23+
# Check if the given stack base dir exists
24+
if [ ! -d ${stack_base_dir} ]
25+
then
26+
error "${stack_base_dir} does not point to an existing directory!"
27+
fi
28+
29+
# Check if Lmod's cache update script can be found at the expected location (in the compatibility layer of the given stack)
30+
update_lmod_system_cache_files="${stack_base_dir}/compat/linux/$(uname -m)/usr/share/Lmod/libexec/update_lmod_system_cache_files"
31+
if [ ! -f ${update_lmod_system_cache_files} ]
32+
then
33+
error "expected to find Lmod's cache update script at ${update_lmod_system_cache_files}, but it doesn't exist."
34+
fi
35+
36+
# Find all subtrees of supported CPU targets by looking for "modules" directories, and taking their parent directory
37+
architectures=$(find ${stack_base_dir}/software/ -maxdepth 5 -type d -name modules -exec dirname {} \;)
38+
39+
# Create/update the Lmod cache for all architectures
40+
for archdir in ${architectures}
41+
do
42+
lmod_cache_dir="${archdir}/.lmod/cache"
43+
${update_lmod_system_cache_files} -d ${lmod_cache_dir} -t ${lmod_cache_dir}/timestamp ${archdir}/modules/all
44+
exit_code=$?
45+
if [[ ${exit_code} -eq 0 ]]; then
46+
echo_green "Updated the Lmod cache for ${archdir}."
47+
ls -lrt ${lmod_cache_dir}
48+
else
49+
echo_red "Updating the Lmod cache failed for ${archdir}."
50+
exit ${exit_code}
51+
fi
52+
done

0 commit comments

Comments
 (0)