Use flock to prevent multiple instances running.

This commit is contained in:
Darren 'Tadgy' Austin 2026-06-27 15:39:53 +01:00
commit 40078e2972

View file

@ -6,6 +6,21 @@ SCANDIR="/data/depository"
DBFILE="/data/sites/slackware.uk/files/repository-search/search.db"
RUNAS_GROUP="depository"
# Only allow one copy of the script to run at any time.
# shellcheck disable=SC2154
if [[ "$FLOCK" != "$0" ]]; then
# shellcheck disable=SC2093
exec env FLOCK="$0" flock -E 10 -e -n "$0" "$0" "$@"
ERR="$?"
if (( ERR == 10 )); then
# File is locked, exit now.
exit 0
elif (( ERR > 0 )); then
printf "%s: %s\\n" "${0##*/}" "flock execution error" >&2
exit 1
fi
fi
RAND="$$$RANDOM"
if ionice -c3 nice -n 19 sg "$RUNAS_GROUP" -c "/opt/bin/updatedb -l no -o \"$DBFILE.$RAND\" -U \"$SCANDIR\" >/dev/null 2>&1"; then