Files
youlegames/codes/agent/game-docker/docker/syncjob/sync.sh
2026-04-10 16:44:13 +08:00

37 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# 定时同步任务:每 SYNC_INTERVAL 秒 POST 请求 dlweb 容器的 Synchronize.php
# 通过 Docker 内网直连,不走域名/公网流量
# 支持暂停:当 /shared/syncjob.pause 文件存在时,跳过本轮请求
# 安装 curl仅首次后续重启容器时已安装则跳过
command -v curl > /dev/null 2>&1 || apk add --no-cache curl > /dev/null 2>&1
SYNC_URL="${SYNC_URL:-http://dlweb/ext/Synchronize.php}"
SYNC_INTERVAL="${SYNC_INTERVAL:-30}"
SYNC_PROCESSCOUNT="${SYNC_PROCESSCOUNT:-200}"
PAUSE_FILE="/shared/syncjob.pause"
echo "[syncjob] target: ${SYNC_URL}?processcount=${SYNC_PROCESSCOUNT}"
echo "[syncjob] interval: ${SYNC_INTERVAL}s"
while true; do
# 检查暂停信号cronjob 执行期间会创建此文件)
if [ -f "${PAUSE_FILE}" ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] PAUSED (${PAUSE_FILE} exists), skipping..."
sleep "${SYNC_INTERVAL}"
continue
fi
RESULT=$(curl -sf -X POST "${SYNC_URL}?processcount=${SYNC_PROCESSCOUNT}" 2>&1)
EXIT_CODE=$?
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
if [ $EXIT_CODE -eq 0 ]; then
echo "[${TIMESTAMP}] OK: ${RESULT}"
else
echo "[${TIMESTAMP}] FAIL(${EXIT_CODE}): ${RESULT}"
fi
sleep "${SYNC_INTERVAL}"
done