Files
configpolicy/roles/repohost/files/repohost-createrepo.sh
Dustin C. Hatch 5dbe26fc60 r/repohost: Optimize createrepo queue loop
Instead of waking every 30 seconds, the queue loop in
`repohost-createrepo.sh` now only wakes when it receives an inotify
event indicating the queue file has been modified.  To avoid missing
events that occured while a `createrepo` process was running, there's
now an inner loop that runs until the queue is completely empty, before
returning to blocking on `inotifywait`.
2025-08-20 07:11:27 -05:00

48 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
QFILE="${HOME}"/createrepo.queue
REPOS_ROOT="${HOME}"/repos
wait_queue() {
inotifywait \
--event close_write \
--include "${QFILE##*/}" \
"${QFILE%/*}"
}
createrepo_loop() {
while wait_queue; do
while [ -f "${QFILE}" ]; do
sleep 10
flock "${QFILE}" mv "${QFILE}" "${QFILE}.work"
sort -u "${QFILE}.work" > "${QFILE}.sorted"
while read dir; do
if [ -d "${dir}" ]; then
printf 'Generating repository metadata for %s\n' "${dir}"
createrepo_c "${dir}"
fi
done < "${QFILE}.sorted"
rm -f "${QFILE}.work" "${QFILE}.sorted"
done
done
}
inotify_loop() {
stdbuf -o 0 inotifywait \
--monitor \
--event close_write,move,delete \
--recursive \
"${REPOS_ROOT}" \
| stdbuf -o 0 grep -E '\.rpm$' \
| while read dir _ _; do
flock "${QFILE}" sh -c 'echo "$1" >> "$2"' -- "${dir}" "${QFILE}"
done
}
mkdir -p "${REPOS_ROOT}"
createrepo_loop &
inotify_loop &
wait