ohmyapi commited on
Commit
e000b8b
·
verified ·
1 Parent(s): f910f00

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +21 -16
entrypoint.sh CHANGED
@@ -2,33 +2,38 @@
2
  #
3
  # entrypoint.sh - Start crond for scheduled cleanup, then launch CLIProxyAPI
4
  #
5
- # This script:
6
- # 1. Sets up the crontab for periodic token cleanup
7
- # 2. Starts busybox crond in background
8
- # 3. Launches the main cli-proxy-api service in foreground
 
 
9
  #
10
 
11
  set -e
12
 
13
  echo "[entrypoint] Starting up at $(date)"
14
 
15
- # Write crontab for token cleanup
16
- # Runs every 6 hours: at 0:00, 6:00, 12:00, 18:00
17
- mkdir -p /etc/cron.d
18
- cat > /etc/crontabs/root << 'EOF'
19
- # CLIProxyAPI invalid token cleanup - runs every 6 hours
20
- 0 */6 * * * /app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
 
 
 
21
  EOF
22
 
23
- # Ensure log directory exists
24
- mkdir -p /tmp/logs
25
 
26
  # Start crond (busybox)
27
- echo "[entrypoint] Starting crond..."
28
  crond -l 8 -L /tmp/logs/crond.log
29
-
30
  echo "[entrypoint] crond started"
31
- echo "[entrypoint] Launching cli-proxy-api..."
32
 
33
- # Hand off to main process (becomes PID 1)
 
 
 
 
34
  exec /app/cli-proxy-api --config /app/config.yaml "$@"
 
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
+ # Examples:
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
+
22
+ # Write crontab
23
+ cat > /etc/crontabs/root << EOF
24
+ # CLIProxyAPI invalid token cleanup
25
+ ${CLEANUP_CRON_SCHEDULE} /app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1
26
  EOF
27
 
28
+ echo "[entrypoint] Cleanup schedule: ${CLEANUP_CRON_SCHEDULE}"
 
29
 
30
  # Start crond (busybox)
 
31
  crond -l 8 -L /tmp/logs/crond.log
 
32
  echo "[entrypoint] crond started"
 
33
 
34
+ # Run cleanup once immediately on startup (in background, so main service starts without waiting)
35
+ echo "[entrypoint] Running initial token cleanup in background..."
36
+ (/app/cleanup_tokens.sh >> /tmp/logs/cleanup.log 2>&1) &
37
+
38
+ echo "[entrypoint] Launching cli-proxy-api..."
39
  exec /app/cli-proxy-api --config /app/config.yaml "$@"