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`.
master
Dustin 2025-08-16 09:22:51 -05:00
parent 2d51e2001d
commit 5dbe26fc60
1 changed files with 21 additions and 9 deletions

View File

@ -1,18 +1,30 @@
#!/bin/sh #!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
QFILE="${HOME}"/createrepo.queue QFILE="${HOME}"/createrepo.queue
REPOS_ROOT="${HOME}"/repos REPOS_ROOT="${HOME}"/repos
wait_queue() {
inotifywait \
--event close_write \
--include "${QFILE##*/}" \
"${QFILE%/*}"
}
createrepo_loop() { createrepo_loop() {
while sleep 30; do while wait_queue; do
[ -f "${QFILE}" ] || continue while [ -f "${QFILE}" ]; do
mv "${QFILE}" "${QFILE}.work" sleep 10
sort -u "${QFILE}.work" > "${QFILE}.sorted" flock "${QFILE}" mv "${QFILE}" "${QFILE}.work"
while read dir; do sort -u "${QFILE}.work" > "${QFILE}.sorted"
printf 'Generating repository metadata for %s\n' "${dir}" while read dir; do
createrepo_c "${dir}" if [ -d "${dir}" ]; then
done < "${QFILE}.sorted" printf 'Generating repository metadata for %s\n' "${dir}"
rm -f "${QFILE}.work" "${QFILE}.sorted" createrepo_c "${dir}"
fi
done < "${QFILE}.sorted"
rm -f "${QFILE}.work" "${QFILE}.sorted"
done
done done
} }