File size: 1,963 Bytes
9727ff0 492f303 9727ff0 492f303 9727ff0 492f303 9727ff0 492f303 9727ff0 492f303 9727ff0 492f303 6f54bdd 492f303 6f54bdd 492f303 6f54bdd 9727ff0 492f303 9727ff0 492f303 9727ff0 492f303 9727ff0 492f303 9727ff0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #!/bin/sh
#
# entrypoint.sh - Launch CLIProxyAPI, optionally with scheduled token cleanup
#
# Set ENABLE_CLEANUP=true to activate automatic invalid token cleanup.
# When disabled (default), behaves identically to a plain CMD ["./cli-proxy-api"].
#
if [ "${ENABLE_CLEANUP}" = "true" ]; then
echo "[entrypoint] Cleanup enabled, starting up at $(date)"
CLEANUP_CRON_SCHEDULE="${CLEANUP_CRON_SCHEDULE:-0 */6 * * *}"
CLEANUP_STARTUP_DELAY="${CLEANUP_STARTUP_DELAY:-10}"
CRON_OK=0
mkdir -p /tmp/logs /tmp/crontabs
# Wrapper script that injects env vars (busybox crond doesn't inherit them)
cat > /tmp/run_cleanup.sh << WRAPPER
#!/bin/sh
export MANAGEMENT_PASSWORD='$(printf '%s' "$MANAGEMENT_PASSWORD" | sed "s/'/'\\\\''/g")'
export FEISHU_WEBHOOK_URL='$(printf '%s' "$FEISHU_WEBHOOK_URL" | sed "s/'/'\\\\''/g")'
export CLEANUP_CONCURRENCY='${CLEANUP_CONCURRENCY:-20}'
exec /app/cleanup_tokens.sh
WRAPPER
chmod +x /tmp/run_cleanup.sh
cat > /tmp/crontabs/root << EOF
${CLEANUP_CRON_SCHEDULE} /tmp/run_cleanup.sh >> /tmp/logs/cleanup.log 2>&1
EOF
echo "[entrypoint] Cleanup schedule: ${CLEANUP_CRON_SCHEDULE}"
if crond -c /tmp/crontabs -l 8 -L /tmp/logs/crond.log 2>/dev/null; then
echo "[entrypoint] crond started"
CRON_OK=1
else
echo "[entrypoint] WARNING: crond failed, will use sleep-loop fallback"
fi
(
MAX_WAIT=120; WAITED=0
while ! wget -q -O /dev/null http://localhost:7860/ 2>/dev/null; do
sleep 2; WAITED=$((WAITED + 2))
[ "$WAITED" -ge "$MAX_WAIT" ] && break
done
sleep "${CLEANUP_STARTUP_DELAY}"
/app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
if [ "$CRON_OK" = "0" ]; then
while true; do
sleep 21600
/app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
done
fi
) &
fi
exec /app/cli-proxy-api --config /app/config.yaml "$@"
|