shenhao-stu commited on
Commit ·
5abf60c
1
Parent(s): bb4eb6e
fix: wait for API ready before running initial token cleanup
Browse files- entrypoint.sh +21 -4
entrypoint.sh
CHANGED
|
@@ -8,14 +8,15 @@
|
|
| 8 |
# "0 */1 * * *" every hour
|
| 9 |
# "0 */6 * * *" every 6 hours (default)
|
| 10 |
# "0 2 * * *" daily at 2:00 AM
|
|
|
|
| 11 |
#
|
| 12 |
|
| 13 |
set -e
|
| 14 |
|
| 15 |
echo "[entrypoint] Starting up at $(date)"
|
| 16 |
|
| 17 |
-
# Default cleanup schedule: every 6 hours
|
| 18 |
CLEANUP_CRON_SCHEDULE="${CLEANUP_CRON_SCHEDULE:-0 */6 * * *}"
|
|
|
|
| 19 |
|
| 20 |
mkdir -p /tmp/logs /etc/crontabs
|
| 21 |
|
|
@@ -31,9 +32,25 @@ echo "[entrypoint] Cleanup schedule: ${CLEANUP_CRON_SCHEDULE}"
|
|
| 31 |
crond -l 8 -L /tmp/logs/crond.log
|
| 32 |
echo "[entrypoint] crond started"
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
echo "[entrypoint] Launching cli-proxy-api..."
|
| 39 |
exec /app/cli-proxy-api --config /app/config.yaml "$@"
|
|
|
|
| 8 |
# "0 */1 * * *" every hour
|
| 9 |
# "0 */6 * * *" every 6 hours (default)
|
| 10 |
# "0 2 * * *" daily at 2:00 AM
|
| 11 |
+
# CLEANUP_STARTUP_DELAY - Seconds to wait after service is ready before first cleanup (default: 10)
|
| 12 |
#
|
| 13 |
|
| 14 |
set -e
|
| 15 |
|
| 16 |
echo "[entrypoint] Starting up at $(date)"
|
| 17 |
|
|
|
|
| 18 |
CLEANUP_CRON_SCHEDULE="${CLEANUP_CRON_SCHEDULE:-0 */6 * * *}"
|
| 19 |
+
CLEANUP_STARTUP_DELAY="${CLEANUP_STARTUP_DELAY:-10}"
|
| 20 |
|
| 21 |
mkdir -p /tmp/logs /etc/crontabs
|
| 22 |
|
|
|
|
| 32 |
crond -l 8 -L /tmp/logs/crond.log
|
| 33 |
echo "[entrypoint] crond started"
|
| 34 |
|
| 35 |
+
# Wait for the API to be ready, then run the initial cleanup in background.
|
| 36 |
+
# This runs in a subshell so it doesn't block the main service from starting.
|
| 37 |
+
(
|
| 38 |
+
echo "[entrypoint] Waiting for API to be ready (polling localhost:7860)..."
|
| 39 |
+
MAX_WAIT=120
|
| 40 |
+
WAITED=0
|
| 41 |
+
while ! wget -q -O /dev/null http://localhost:7860/ 2>/dev/null; do
|
| 42 |
+
sleep 2
|
| 43 |
+
WAITED=$((WAITED + 2))
|
| 44 |
+
if [ "$WAITED" -ge "$MAX_WAIT" ]; then
|
| 45 |
+
echo "[entrypoint] WARNING: API did not become ready after ${MAX_WAIT}s, running cleanup anyway"
|
| 46 |
+
break
|
| 47 |
+
fi
|
| 48 |
+
done
|
| 49 |
+
echo "[entrypoint] API ready (waited ${WAITED}s). Sleeping ${CLEANUP_STARTUP_DELAY}s before cleanup..."
|
| 50 |
+
sleep "$CLEANUP_STARTUP_DELAY"
|
| 51 |
+
echo "[entrypoint] Running initial token cleanup..."
|
| 52 |
+
/app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
|
| 53 |
+
) &
|
| 54 |
|
| 55 |
echo "[entrypoint] Launching cli-proxy-api..."
|
| 56 |
exec /app/cli-proxy-api --config /app/config.yaml "$@"
|