8900 commited on
Commit
3612cfa
Β·
verified Β·
1 Parent(s): 4b3e191

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +37 -39
entrypoint.sh CHANGED
@@ -2,72 +2,70 @@
2
 
3
  # OpenClaw HF Spaces - Production Entrypoint
4
 
5
- # NO set -e: we handle errors explicitly to avoid silent crashes
6
 
7
- # –– resolve writable home β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
8
 
9
  if mkdir -p /data/.openclaw 2>/dev/null; then
10
- export OPENCLAW_HOME=/data
11
  else
12
- export OPENCLAW_HOME=/home/user
13
- mkdir -p /home/user/.openclaw
14
  fi
15
  echo "[entrypoint] OPENCLAW_HOME=$OPENCLAW_HOME"
16
 
17
- # –– dynamic provider key export β€”β€”β€”β€”β€”β€”β€”β€”β€”
18
 
19
- # Export any env var matching provider key patterns.
 
20
  # Matches: *_API_KEY *_SECRET_KEY *_ACCESS_TOKEN
21
  # *_BOT_TOKEN *_AUTH_TOKEN *_APP_KEY
22
  # Excludes: OPENCLAW_ SPACE_ SYSTEM_ HF_ NODE_ npm_ prefixes
23
 
24
  for VAR in $(env | cut -d= -f1); do
25
- case "$VAR" in
26
- OPENCLAW_*|SPACE_*|SYSTEM_*|HF_*|NODE_*|npm_*) continue ;;
27
- esac
28
- case "$VAR" in
29
- *_API_KEY|*_SECRET_KEY|*_ACCESS_TOKEN|*_BOT_TOKEN|*_AUTH_TOKEN|*_APP_KEY)
30
- VAL=$(printenv "$VAR" 2>/dev/null || true)
31
- if [ -n "$VAL" ]; then
32
- export "$VAR"
33
- echo "[entrypoint] exported: $VAR"
34
- fi
35
- ;;
36
- esac
 
37
  done
38
 
39
- # always export HF_TOKEN for dataset sync
40
  export HF_TOKEN="${HF_TOKEN:-}"
41
 
42
- # –– restore from HF Dataset (non-blocking) ––––––––
43
- if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ]; then
44
- echo "[entrypoint] Restoring from dataset ${HF_DATASET_ID}..."
45
- if command -v timeout >/dev/null 2>&1; then
46
- timeout 30 sh /app/hf-sync.sh restore || true
47
- else
48
- sh /app/hf-sync.sh restore || true
49
- fi
50
- fi
51
 
52
- # –– write openclaw config β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
53
  echo "[entrypoint] Running setup..."
54
  node /app/spaces/huggingface/setup-hf-config.mjs || true
55
  echo "[entrypoint] Setup done."
56
 
57
- # –– security audit (non-fatal) ––––––––––––––
 
58
  if [ -f /app/security-check.sh ]; then
59
- sh /app/security-check.sh || true
60
  fi
61
 
62
- # –– start background dataset sync loop ––––––––––
63
- if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ]; then
64
- sh /app/hf-sync.sh loop &
65
- echo "[entrypoint] sync loop started (interval=${HF_SYNC_INTERVAL:-3600}s)"
 
 
 
 
66
  fi
67
 
68
  echo "[entrypoint] Starting gateway..."
69
 
70
  exec node /app/openclaw.mjs gateway \
71
- --allow-unconfigured \
72
- --bind lan \
73
- --port 7860
 
2
 
3
  # OpenClaw HF Spaces - Production Entrypoint
4
 
5
+ # Sync code removed: handled by hf-sync-manager.mjs (background process)
6
 
7
+ # -- resolve writable home -----------------------
8
 
9
  if mkdir -p /data/.openclaw 2>/dev/null; then
10
+ export OPENCLAW_HOME=/data
11
  else
12
+ export OPENCLAW_HOME=/home/user
13
+ mkdir -p /home/user/.openclaw
14
  fi
15
  echo "[entrypoint] OPENCLAW_HOME=$OPENCLAW_HOME"
16
 
17
+ # -- dynamic provider key export -----------------
18
 
19
+ # Export any env var that looks like a provider API key so the
20
+ # openclaw gateway process can read it at runtime.
21
  # Matches: *_API_KEY *_SECRET_KEY *_ACCESS_TOKEN
22
  # *_BOT_TOKEN *_AUTH_TOKEN *_APP_KEY
23
  # Excludes: OPENCLAW_ SPACE_ SYSTEM_ HF_ NODE_ npm_ prefixes
24
 
25
  for VAR in $(env | cut -d= -f1); do
26
+ case "$VAR" in
27
+ OPENCLAW_*|SPACE_*|SYSTEM_*|HF_*|NODE_*|npm_*) continue ;;
28
+ esac
29
+ case "$VAR" in
30
+ *_API_KEY|*_SECRET_KEY|*_ACCESS_TOKEN| \
31
+ *_BOT_TOKEN|*_AUTH_TOKEN|*_APP_KEY)
32
+ VAL=$(printenv "$VAR" 2>/dev/null || true)
33
+ if [ -n "$VAL" ]; then
34
+ export "$VAR"
35
+ echo "[entrypoint] exported: $VAR"
36
+ fi
37
+ ;;
38
+ esac
39
  done
40
 
41
+ # HF_TOKEN exported separately (excluded above, needed by sync manager)
42
  export HF_TOKEN="${HF_TOKEN:-}"
43
 
44
+ # -- write openclaw config -----------------------
 
 
 
 
 
 
 
 
45
 
 
46
  echo "[entrypoint] Running setup..."
47
  node /app/spaces/huggingface/setup-hf-config.mjs || true
48
  echo "[entrypoint] Setup done."
49
 
50
+ # -- security audit (non-fatal) ------------------
51
+
52
  if [ -f /app/security-check.sh ]; then
53
+ sh /app/security-check.sh || true
54
  fi
55
 
56
+ # -- start sync manager in background ------------
57
+
58
+ # Handles HF Dataset sync + Telegram bot commands independently
59
+ # Never restarts gateway or HF Space
60
+
61
+ if [ -f /app/hf-sync-manager.mjs ]; then
62
+ node /app/hf-sync-manager.mjs &
63
+ echo "[entrypoint] Sync manager started (PID $!)"
64
  fi
65
 
66
  echo "[entrypoint] Starting gateway..."
67
 
68
  exec node /app/openclaw.mjs gateway \
69
+ --allow-unconfigured \
70
+ --bind lan \
71
+ --port 7860