mirror of
https://github.com/rocky-linux/rocky-tools.git
synced 2024-11-22 13:11:26 +00:00
Update mirrorsync.sh
Added dead process check to file locking
This commit is contained in:
parent
00a6125036
commit
f80797de04
@ -53,6 +53,8 @@ filelistfile="fullfiletimelist-rocky"
|
|||||||
lockfile="$0.lockfile"
|
lockfile="$0.lockfile"
|
||||||
logfile="$0.log"
|
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}")
|
checkresult=$(${rsync} --no-motd --dry-run --out-format="%n" "${src}/${filelistfile}" "${dst}/${filelistfile}")
|
||||||
if [[ -z "$checkresult" ]]; then
|
if [[ -z "$checkresult" ]]; then
|
||||||
printf "%s unchanged. Not updating at %(%c)T\n" "$filelistfile" -1 >> "$logfile" 2>&1
|
printf "%s unchanged. Not updating at %(%c)T\n" "$filelistfile" -1 >> "$logfile" 2>&1
|
||||||
@ -60,17 +62,23 @@ if [[ -z "$checkresult" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check for existing lockfile to avoid multiple simultaneously running syncs
|
||||||
if [[ -e "$lockfile" ]]; then
|
# 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
|
printf "Update already in progress at %(%c)T\n" -1 >> "$logfile" 2>&1
|
||||||
logger -t rsync "Not updating ${mirrormodule}: already in progress."
|
logger -t rsync "Not updating ${mirrormodule}: already in progress."
|
||||||
else
|
exit 1
|
||||||
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
|
|
||||||
fi
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user