diff --git a/platform/shell-sync/sync.sh b/platform/shell-sync/sync.sh index 757879dc..490f5db6 100644 --- a/platform/shell-sync/sync.sh +++ b/platform/shell-sync/sync.sh @@ -336,3 +336,27 @@ start_heartbeat() { HEARTBEAT_PID=$! } +run_cron_scheduler() { + local wrapper="${PID_DIR}/cron-sync-all.sh" + local crontab_file="${PID_DIR}/sync.crontab" + + # Cron starts commands with a minimal environment. Preserve this container's + # configuration in a root-only Bash wrapper so arbitrary ACCOUNT_N_* values work. + { + printf '#!/bin/bash\n' + export -p + printf 'exec /sync.sh sync-all\n' + } > "$wrapper" + chmod 700 "$wrapper" + printf '%s %s >> /proc/1/fd/1 2>&1\n' "$SYNC_CRON" "$wrapper" > "$crontab_file" + + if ! crontab "$crontab_file"; then + log "Configuration error: SYNC_CRON is not a valid cron expression: $SYNC_CRON" + return 1 + fi + log "Starting cron schedule: $SYNC_CRON" + cron -f & + CRON_PID=$! + wait "$CRON_PID" +} +