Update mirrorsync.sh

Added dead process check to file locking
This commit is contained in:
Dennis Körner 2021-06-03 12:25:32 +02:00 committed by GitHub
parent 00a6125036
commit f80797de04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 11 deletions

View File

@ -53,6 +53,8 @@ filelistfile="fullfiletimelist-rocky"
lockfile="$0.lockfile"
logfile="$0.log"
# Check if the filelistfile has changed on upstream mirror
# and exit if it is still the same
checkresult=$(${rsync} --no-motd --dry-run --out-format="%n" "${src}/${filelistfile}" "${dst}/${filelistfile}")
if [[ -z "$checkresult" ]]; then
printf "%s unchanged. Not updating at %(%c)T\n" "$filelistfile" -1 >> "$logfile" 2>&1
@ -60,17 +62,23 @@ if [[ -z "$checkresult" ]]; then
exit 1
fi
if [[ -e "$lockfile" ]]; then
# Check for existing lockfile to avoid multiple simultaneously running syncs
# If lockfile exists but process is dead continue anyway
if [[ -e "$lockfile" ]] && ! kill -0 "$(< "$lockfile")"; then
printf "Warning: lockfile exists but process dead, continuing.\n" >> "$logfile" 2>&1
logger -t rsync "Warning: lockfile exists but process dead, continuing with updating ${mirrormodule}."
rm -f "$lockfile"
elif [[ -e "$lockfile" ]]; then
printf "Update already in progress at %(%c)T\n" -1 >> "$logfile" 2>&1
logger -t rsync "Not updating ${mirrormodule}: already in progress."
else
touch $lockfile
printf "Started update at %(%c)T\n" -1 >> "$logfile" 2>&1
logger -t rsync "Updating ${mirrormodule}"
${rsync} "${opts[@]}" "${src}/" "${dst}/" >> "$logfile" 2>&1
logger -t rsync "Finished updating ${mirrormodule}"
printf "End: %(%c)T\n" -1 >> "$logfile" 2>&1
rm -f $lockfile
exit 1
fi
# The actual syncing part
printf '%s\n' "$$" > "$lockfile"
printf "Started update at %(%c)T\n" -1 >> "$logfile" 2>&1
logger -t rsync "Updating ${mirrormodule}"
${rsync} "${opts[@]}" "${src}/" "${dst}/" >> "$logfile" 2>&1
logger -t rsync "Finished updating ${mirrormodule}"
printf "End: %(%c)T\n" -1 >> "$logfile" 2>&1
rm -f $lockfile