8900 commited on
Update entrypoint.sh
Browse files- 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
|
| 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
|
| 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 |
-
# ββ
|
| 65 |
|
| 66 |
-
#
|
| 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 |
-
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
while true; do
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
| 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
|