ohmyapi commited on
Commit
2927da7
·
verified ·
1 Parent(s): 946f32c

fix: complete solution - entrypoint with /tmp/crontabs + config without pgstore-dsn

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. entrypoint.sh +53 -2
Dockerfile CHANGED
@@ -18,4 +18,4 @@ RUN chmod +x /app/cleanup_tokens.sh /app/entrypoint.sh
18
  ENV TZ=Asia/Shanghai
19
  EXPOSE 7860
20
 
21
- CMD ["./cli-proxy-api", "--config", "/app/config.yaml"]
 
18
  ENV TZ=Asia/Shanghai
19
  EXPOSE 7860
20
 
21
+ CMD ["/app/entrypoint.sh"]
entrypoint.sh CHANGED
@@ -1,3 +1,54 @@
1
  #!/bin/sh
2
- echo "[entrypoint] starting"
3
- exec /app/cli-proxy-api --config /app/config.yaml
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/bin/sh
2
+ #
3
+ # entrypoint.sh - Start crond for scheduled cleanup, then launch CLIProxyAPI
4
+ #
5
+ # Environment variables:
6
+ # CLEANUP_CRON_SCHEDULE - Cron schedule for token cleanup (default: "0 */6 * * *", every 6h)
7
+ # CLEANUP_STARTUP_DELAY - Seconds to wait after service is ready before first cleanup (default: 10)
8
+ #
9
+
10
+ echo "[entrypoint] Starting up at $(date)"
11
+
12
+ CLEANUP_CRON_SCHEDULE="${CLEANUP_CRON_SCHEDULE:-0 */6 * * *}"
13
+ CLEANUP_STARTUP_DELAY="${CLEANUP_STARTUP_DELAY:-10}"
14
+ CRON_OK=0
15
+
16
+ mkdir -p /tmp/logs /tmp/crontabs
17
+
18
+ # Write crontab to /tmp (HuggingFace root filesystem is read-only)
19
+ cat > /tmp/crontabs/root << EOF
20
+ ${CLEANUP_CRON_SCHEDULE} /app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
21
+ EOF
22
+
23
+ echo "[entrypoint] Cleanup schedule: ${CLEANUP_CRON_SCHEDULE}"
24
+
25
+ # Try crond; if it fails, fall back to a sleep loop
26
+ if crond -c /tmp/crontabs -l 8 -L /tmp/logs/crond.log 2>/dev/null; then
27
+ echo "[entrypoint] crond started"
28
+ CRON_OK=1
29
+ else
30
+ echo "[entrypoint] WARNING: crond failed, will use sleep-loop fallback"
31
+ fi
32
+
33
+ # Background: wait for API ready, run initial cleanup, then optionally loop
34
+ (
35
+ MAX_WAIT=120
36
+ WAITED=0
37
+ while ! wget -q -O /dev/null http://localhost:7860/ 2>/dev/null; do
38
+ sleep 2
39
+ WAITED=$((WAITED + 2))
40
+ [ "$WAITED" -ge "$MAX_WAIT" ] && break
41
+ done
42
+ sleep "${CLEANUP_STARTUP_DELAY}"
43
+ /app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
44
+
45
+ if [ "$CRON_OK" = "0" ]; then
46
+ while true; do
47
+ sleep 21600
48
+ /app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
49
+ done
50
+ fi
51
+ ) &
52
+
53
+ echo "[entrypoint] Launching cli-proxy-api..."
54
+ exec /app/cli-proxy-api --config /app/config.yaml "$@"