Document scheduled WCX updates
This commit is contained in:
53
scripts/scheduled_update_wcx.sh
Executable file
53
scripts/scheduled_update_wcx.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Run the WCX update at most once every 48 hours.
|
||||
#
|
||||
# The systemd timer invokes this script every night. The timestamp file is
|
||||
# updated only after a successful WCX update.
|
||||
#
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
ROOT_DIR="/storage/disk1/WCX"
|
||||
|
||||
UPDATE_SCRIPT="${ROOT_DIR}/scripts/update_wcx.sh"
|
||||
STAMP_FILE="${ROOT_DIR}/database/last_scheduled_update"
|
||||
|
||||
MINIMUM_INTERVAL_SECONDS=$((47 * 60 * 60))
|
||||
|
||||
|
||||
log() {
|
||||
printf '[%s] %s\n' \
|
||||
"$(date '+%Y-%m-%d %H:%M:%S')" \
|
||||
"$*"
|
||||
}
|
||||
|
||||
|
||||
if [[ ! -x "${UPDATE_SCRIPT}" ]]; then
|
||||
log "ERROR: Update script is missing or not executable: ${UPDATE_SCRIPT}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [[ -f "${STAMP_FILE}" ]]; then
|
||||
current_time=$(date +%s)
|
||||
previous_time=$(stat -c %Y "${STAMP_FILE}")
|
||||
elapsed_seconds=$((current_time - previous_time))
|
||||
|
||||
if (( elapsed_seconds < MINIMUM_INTERVAL_SECONDS )); then
|
||||
elapsed_hours=$((elapsed_seconds / 3600))
|
||||
|
||||
log "Skipping update; previous successful scheduled run was ${elapsed_hours} hours ago."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
log "Starting scheduled WCX update."
|
||||
|
||||
"${UPDATE_SCRIPT}"
|
||||
|
||||
touch "${STAMP_FILE}"
|
||||
|
||||
log "Scheduled WCX update completed successfully."
|
||||
Reference in New Issue
Block a user