8900 commited on
Commit
bdea495
Β·
verified Β·
1 Parent(s): 9d17588

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +30 -6
entrypoint.sh CHANGED
@@ -2,7 +2,13 @@
2
 
3
  # OpenClaw HF Spaces - Production Entrypoint
4
 
5
- # Setup always runs - but setup.mjs patches existing config, never overwrites.
 
 
 
 
 
 
6
 
7
  # –– resolve writable home β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
8
 
@@ -33,7 +39,10 @@ done
33
 
34
  export HF_TOKEN="${HF_TOKEN:-}"
35
 
36
- # –– run setup β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
 
 
 
37
 
38
  echo "[entrypoint] Running setup…"
39
  node /app/spaces/huggingface/setup-hf-config.mjs || true
@@ -45,16 +54,31 @@ if [ -f /app/security-check.sh ]; then
45
  sh /app/security-check.sh || true
46
  fi
47
 
48
- # –– start sync manager in background –––––––––––
49
 
50
  if [ -f /app/hf-sync-manager.mjs ]; then
51
  (node /app/hf-sync-manager.mjs &)
52
  echo "[entrypoint] Sync manager started"
53
  fi
54
 
55
- echo "[entrypoint] Starting gateway…"
 
 
 
 
 
 
 
56
 
57
- exec node /app/openclaw.mjs gateway \
 
 
 
58
  --allow-unconfigured \
59
  --bind lan \
60
- --port 7860
 
 
 
 
 
 
2
 
3
  # OpenClaw HF Spaces - Production Entrypoint
4
 
5
+ #
6
+ # KEY: gateway runs in a while loop.
7
+ # When OpenClaw does β€œfull process restart” (on config save),
8
+ # the gateway process exits but the container stays alive.
9
+ # The loop catches the exit and restarts the gateway in ~1 second.
10
+ # This eliminates: container crash, 1005/1006 permanent errors,
11
+ # settings overwrite (setup only runs once per container lifetime).
12
 
13
  # –– resolve writable home β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
14
 
 
39
 
40
  export HF_TOKEN="${HF_TOKEN:-}"
41
 
42
+ # –– run setup ONCE ––––––––––––––––––––
43
+
44
+ # setup.mjs uses patch mode: if openclaw.json exists, only update
45
+ # auth/env.vars/channels, never overwrite user settings.
46
 
47
  echo "[entrypoint] Running setup…"
48
  node /app/spaces/huggingface/setup-hf-config.mjs || true
 
54
  sh /app/security-check.sh || true
55
  fi
56
 
57
+ # –– start sync manager ONCE in background —————–
58
 
59
  if [ -f /app/hf-sync-manager.mjs ]; then
60
  (node /app/hf-sync-manager.mjs &)
61
  echo "[entrypoint] Sync manager started"
62
  fi
63
 
64
+ # –– gateway loop β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
65
+
66
+ # OpenClaw β€œfull process restart” exits the gateway process (code 0).
67
+ # Without this loop: container exits -> HF stops container -> crash.
68
+ # With this loop: exit caught -> restart in 1s -> container stays alive.
69
+ # Users see: brief 1005/1006 disconnect -> auto-reconnect in ~5-10s.
70
+
71
+ echo "[entrypoint] Starting gateway loop…"
72
 
73
+ while true; do
74
+ echo "[entrypoint] Gateway starting…"
75
+
76
+ node /app/openclaw.mjs gateway \
77
  --allow-unconfigured \
78
  --bind lan \
79
+ --port 7860
80
+
81
+ EXIT_CODE=$?
82
+ echo "[entrypoint] Gateway exited (code $EXIT_CODE) - restarting in 2s…"
83
+ sleep 2
84
+ done