8900 commited on
Commit
c0df9f7
Β·
verified Β·
1 Parent(s): 7748523

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +59 -24
entrypoint.sh CHANGED
@@ -2,14 +2,6 @@
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
 
15
  if mkdir -p /data/.openclaw 2>/dev/null; then
@@ -39,10 +31,7 @@ done
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,30 +43,76 @@ if [ -f /app/security-check.sh ]; then
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
 
2
 
3
  # OpenClaw HF Spaces - Production Entrypoint
4
 
 
 
 
 
 
 
 
 
5
  # –– resolve writable home β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
6
 
7
  if mkdir -p /data/.openclaw 2>/dev/null; then
 
31
 
32
  export HF_TOKEN="${HF_TOKEN:-}"
33
 
34
+ # –– run setup (patch mode: preserves user settings) —––
 
 
 
35
 
36
  echo "[entrypoint] Running setup…"
37
  node /app/spaces/huggingface/setup-hf-config.mjs || true
 
43
  sh /app/security-check.sh || true
44
  fi
45
 
46
+ # –– start sync manager in background –––––––––––
47
 
48
  if [ -f /app/hf-sync-manager.mjs ]; then
49
  (node /app/hf-sync-manager.mjs &)
50
  echo "[entrypoint] Sync manager started"
51
  fi
52
 
53
+ # –– auto-approve pending device pairings β€”β€”β€”β€”β€”β€”
54
 
55
+ # Sub-agents connecting as nodes require device pairing.
 
 
 
56
 
57
+ # This loop detects pending pairing requests and approves them automatically.
58
 
59
+ (
60
+ DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
61
+ mkdir -p "$DEVICES_DIR"
62
+ echo "[auto-pair] Device auto-approval started"
63
  while true; do
64
+ sleep 8
65
+ PENDING="$DEVICES_DIR/pending.json"
66
+ PAIRED="$DEVICES_DIR/paired.json"
67
+ if [ -f "$PENDING" ]; then
68
+ node - << 'JSEOF'
69
+ const fs = require('fs');
70
+ const devDir = process.env.OPENCLAW_HOME + '/.openclaw/devices';
71
+ const pendingPath = devDir + '/pending.json';
72
+ const pairedPath = devDir + '/paired.json';
73
+ try {
74
+ const raw = fs.readFileSync(pendingPath, 'utf-8').trim();
75
+ if (!raw || raw === '[]' || raw === '{}') process.exit(0);
76
+ let pending = JSON.parse(raw);
77
+ if (!Array.isArray(pending)) pending = Object.values(pending);
78
+ if (pending.length === 0) process.exit(0);
79
+ let paired = [];
80
+ if (fs.existsSync(pairedPath)) {
81
+ try { paired = JSON.parse(fs.readFileSync(pairedPath, 'utf-8')); } catch(e) {}
82
+ }
83
+ if (!Array.isArray(paired)) paired = [];
84
+ const pairedIds = new Set(paired.map(function(d) { return d.id || d.deviceId || d.name; }));
85
+ const toApprove = pending.filter(function(d) {
86
+ return !pairedIds.has(d.id || d.deviceId || d.name);
87
+ });
88
+ if (toApprove.length > 0) {
89
+ const approved = toApprove.map(function(d) {
90
+ return Object.assign({}, d, { approved: true, approvedAt: new Date().toISOString() });
91
+ });
92
+ paired = paired.concat(approved);
93
+ fs.writeFileSync(pairedPath, JSON.stringify(paired, null, 2));
94
+ fs.writeFileSync(pendingPath, '[]');
95
+ console.log('[auto-pair] Approved ' + toApprove.length + ' device(s)');
96
+ }
97
+ } catch(e) { /* ignore */ }
98
+ JSEOF
99
+ fi
100
+ done
101
+ ) &
102
 
103
+ # –– gateway loop β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
104
+
105
+ # Gateway exits on config save (OpenClaw full process restart).
106
+
107
+ # Loop keeps container alive and restarts gateway in 2s.
108
 
109
+ echo "[entrypoint] Starting gateway loop…"
110
+ while true; do
111
+ echo "[entrypoint] Gateway starting…"
112
+ node /app/openclaw.mjs gateway
113
+ –allow-unconfigured
114
+ –bind lan
115
+ –port 7860
116
  EXIT_CODE=$?
117
  echo "[entrypoint] Gateway exited (code $EXIT_CODE) - restarting in 2s…"
118
  sleep 2