Dateien nach "docker/syncer" hochladen
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
# Container entrypoint: run sync.sh once, or in a loop every
|
||||
# SYNC_INTERVAL_SECONDS. There's no systemd/cron inside the container, so a
|
||||
# simple sleep-loop is the pragmatic choice.
|
||||
set -euo pipefail
|
||||
|
||||
: "${SYNC_INTERVAL_SECONDS:=3600}"
|
||||
: "${RUN_ONCE:=false}"
|
||||
|
||||
log() { echo "[entrypoint] $(date '+%Y-%m-%d %H:%M:%S') $*"; }
|
||||
|
||||
run_once() {
|
||||
/usr/local/bin/sync.sh
|
||||
}
|
||||
|
||||
if [[ "$RUN_ONCE" == "true" ]]; then
|
||||
log "RUN_ONCE=true - running sync.sh once and exiting"
|
||||
run_once
|
||||
exit $?
|
||||
fi
|
||||
|
||||
log "Starting sync loop (interval: ${SYNC_INTERVAL_SECONDS}s)"
|
||||
|
||||
# Graceful shutdown on docker stop / compose down
|
||||
term_handler() {
|
||||
log "Received SIGTERM, shutting down"
|
||||
exit 0
|
||||
}
|
||||
trap term_handler SIGTERM SIGINT
|
||||
|
||||
while true; do
|
||||
# NOTE: don't inline `run_once` into `if ! run_once; then ...` - inside
|
||||
# that then-branch, $? would reflect the (always-0) negated test itself,
|
||||
# not run_once's real exit code. Capture it explicitly instead.
|
||||
rc=0
|
||||
run_once || rc=$?
|
||||
if [[ $rc -ne 0 ]]; then
|
||||
log "sync.sh failed (exit ${rc}) - will retry after the next interval"
|
||||
fi
|
||||
log "Sleeping ${SYNC_INTERVAL_SECONDS}s until next sync..."
|
||||
sleep "${SYNC_INTERVAL_SECONDS}" &
|
||||
wait $!
|
||||
done
|
||||
Reference in New Issue
Block a user