Update entrypoint.sh
Browse files- entrypoint.sh +16 -31
entrypoint.sh
CHANGED
|
@@ -1,18 +1,15 @@
|
|
| 1 |
#!/bin/sh
|
| 2 |
# OpenClaw HF Spaces - Production Entrypoint
|
| 3 |
-
#
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# ----------------------------------------------------------------
|
| 6 |
-
# Logging
|
| 7 |
-
# ----------------------------------------------------------------
|
| 8 |
ts() { date -u +"%H:%M:%S"; }
|
| 9 |
log() { echo "[$(ts)] [entrypoint] $*"; }
|
| 10 |
warn() { echo "[$(ts)] [entrypoint] WARN: $*"; }
|
| 11 |
|
| 12 |
# ----------------------------------------------------------------
|
| 13 |
# Storage: resolve OPENCLAW_HOME
|
| 14 |
-
# Prefer /data (HF Storage Bucket). Fall back to /home/user.
|
| 15 |
-
# Retry up to 5s in case the bucket mount is slightly delayed.
|
| 16 |
# ----------------------------------------------------------------
|
| 17 |
OPENCLAW_HOME=/home/user
|
| 18 |
mkdir -p /home/user/.openclaw
|
|
@@ -42,43 +39,33 @@ export OPENCLAW_HOME
|
|
| 42 |
log "OPENCLAW_HOME=$OPENCLAW_HOME"
|
| 43 |
|
| 44 |
# ----------------------------------------------------------------
|
| 45 |
-
# Clean up stale/uid-mismatched plugins
|
| 46 |
-
# These cause "suspicious ownership" warnings and block startup.
|
| 47 |
# ----------------------------------------------------------------
|
| 48 |
EXTENSIONS_DIR="$OPENCLAW_HOME/.openclaw/extensions"
|
| 49 |
if [ -d "$EXTENSIONS_DIR" ]; then
|
| 50 |
log "Removing stale extensions dir (uid mismatch fix)..."
|
| 51 |
-
rm -rf "$EXTENSIONS_DIR" || warn "Could not remove extensions dir
|
| 52 |
fi
|
| 53 |
|
| 54 |
-
# Also clean stale plugin config entries from openclaw.json if it exists
|
| 55 |
CONFIG_PATH="$OPENCLAW_HOME/.openclaw/openclaw.json"
|
| 56 |
if [ -f "$CONFIG_PATH" ]; then
|
| 57 |
node - << 'JSEOF' || true
|
| 58 |
const fs = require('fs');
|
| 59 |
const p = process.env.OPENCLAW_HOME + '/.openclaw/openclaw.json';
|
| 60 |
try {
|
| 61 |
-
const
|
| 62 |
-
const cfg = JSON.parse(raw);
|
| 63 |
-
let changed = false;
|
| 64 |
-
// Remove stale plugins section entirely
|
| 65 |
if (cfg.plugins) {
|
| 66 |
delete cfg.plugins;
|
| 67 |
-
changed = true;
|
| 68 |
-
console.log('[entrypoint] Removed stale plugins config from openclaw.json');
|
| 69 |
-
}
|
| 70 |
-
if (changed) {
|
| 71 |
fs.copyFileSync(p, p + '.bak');
|
| 72 |
fs.writeFileSync(p, JSON.stringify(cfg, null, 2), 'utf-8');
|
|
|
|
| 73 |
}
|
| 74 |
-
} catch(e) {
|
| 75 |
-
console.log('[entrypoint] Plugin cleanup skipped: ' + e.message);
|
| 76 |
-
}
|
| 77 |
JSEOF
|
| 78 |
fi
|
| 79 |
|
| 80 |
# ----------------------------------------------------------------
|
| 81 |
-
# Export provider API keys
|
| 82 |
# ----------------------------------------------------------------
|
| 83 |
for VAR in $(env | cut -d= -f1); do
|
| 84 |
case "$VAR" in
|
|
@@ -98,21 +85,18 @@ done
|
|
| 98 |
export HF_TOKEN="${HF_TOKEN:-}"
|
| 99 |
|
| 100 |
# ----------------------------------------------------------------
|
| 101 |
-
#
|
| 102 |
# ----------------------------------------------------------------
|
| 103 |
log "Running setup..."
|
| 104 |
node /app/spaces/huggingface/setup-hf-config.mjs || true
|
| 105 |
log "Setup done."
|
| 106 |
|
| 107 |
-
# ----------------------------------------------------------------
|
| 108 |
-
# Security audit (non-fatal)
|
| 109 |
-
# ----------------------------------------------------------------
|
| 110 |
if [ -f /app/security-check.sh ]; then
|
| 111 |
sh /app/security-check.sh || true
|
| 112 |
fi
|
| 113 |
|
| 114 |
# ----------------------------------------------------------------
|
| 115 |
-
#
|
| 116 |
# ----------------------------------------------------------------
|
| 117 |
(
|
| 118 |
DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
|
|
@@ -147,21 +131,22 @@ try {
|
|
| 147 |
fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
|
| 148 |
fs.writeFileSync(pend, '[]');
|
| 149 |
console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
|
| 150 |
-
} catch(e) {
|
| 151 |
JSEOF
|
| 152 |
fi
|
| 153 |
done
|
| 154 |
) &
|
| 155 |
|
| 156 |
# ----------------------------------------------------------------
|
| 157 |
-
# Gateway loop
|
| 158 |
# ----------------------------------------------------------------
|
| 159 |
log "Starting gateway loop..."
|
|
|
|
| 160 |
|
| 161 |
while true; do
|
| 162 |
log "Gateway starting..."
|
| 163 |
|
| 164 |
-
node
|
| 165 |
--allow-unconfigured \
|
| 166 |
--bind lan \
|
| 167 |
--port 7860
|
|
@@ -172,7 +157,7 @@ while true; do
|
|
| 172 |
WAITED=0
|
| 173 |
while nc -z 127.0.0.1 7860 2>/dev/null; do
|
| 174 |
if [ $WAITED -eq 0 ]; then
|
| 175 |
-
log "Port 7860 still held
|
| 176 |
fi
|
| 177 |
sleep 2
|
| 178 |
WAITED=$((WAITED + 2))
|
|
|
|
| 1 |
#!/bin/sh
|
| 2 |
# OpenClaw HF Spaces - Production Entrypoint
|
| 3 |
+
# OpenClaw binary lives at: /home/node/.openclaw/app/openclaw.mjs
|
| 4 |
+
|
| 5 |
+
OPENCLAW_BIN="${OPENCLAW_APP:-/home/node/.openclaw/app}/openclaw.mjs"
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
ts() { date -u +"%H:%M:%S"; }
|
| 8 |
log() { echo "[$(ts)] [entrypoint] $*"; }
|
| 9 |
warn() { echo "[$(ts)] [entrypoint] WARN: $*"; }
|
| 10 |
|
| 11 |
# ----------------------------------------------------------------
|
| 12 |
# Storage: resolve OPENCLAW_HOME
|
|
|
|
|
|
|
| 13 |
# ----------------------------------------------------------------
|
| 14 |
OPENCLAW_HOME=/home/user
|
| 15 |
mkdir -p /home/user/.openclaw
|
|
|
|
| 39 |
log "OPENCLAW_HOME=$OPENCLAW_HOME"
|
| 40 |
|
| 41 |
# ----------------------------------------------------------------
|
| 42 |
+
# Clean up stale/uid-mismatched plugins
|
|
|
|
| 43 |
# ----------------------------------------------------------------
|
| 44 |
EXTENSIONS_DIR="$OPENCLAW_HOME/.openclaw/extensions"
|
| 45 |
if [ -d "$EXTENSIONS_DIR" ]; then
|
| 46 |
log "Removing stale extensions dir (uid mismatch fix)..."
|
| 47 |
+
rm -rf "$EXTENSIONS_DIR" || warn "Could not remove extensions dir"
|
| 48 |
fi
|
| 49 |
|
|
|
|
| 50 |
CONFIG_PATH="$OPENCLAW_HOME/.openclaw/openclaw.json"
|
| 51 |
if [ -f "$CONFIG_PATH" ]; then
|
| 52 |
node - << 'JSEOF' || true
|
| 53 |
const fs = require('fs');
|
| 54 |
const p = process.env.OPENCLAW_HOME + '/.openclaw/openclaw.json';
|
| 55 |
try {
|
| 56 |
+
const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'));
|
|
|
|
|
|
|
|
|
|
| 57 |
if (cfg.plugins) {
|
| 58 |
delete cfg.plugins;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
fs.copyFileSync(p, p + '.bak');
|
| 60 |
fs.writeFileSync(p, JSON.stringify(cfg, null, 2), 'utf-8');
|
| 61 |
+
console.log('[entrypoint] Removed stale plugins config');
|
| 62 |
}
|
| 63 |
+
} catch(e) { console.log('[entrypoint] Plugin cleanup skipped: ' + e.message); }
|
|
|
|
|
|
|
| 64 |
JSEOF
|
| 65 |
fi
|
| 66 |
|
| 67 |
# ----------------------------------------------------------------
|
| 68 |
+
# Export provider API keys
|
| 69 |
# ----------------------------------------------------------------
|
| 70 |
for VAR in $(env | cut -d= -f1); do
|
| 71 |
case "$VAR" in
|
|
|
|
| 85 |
export HF_TOKEN="${HF_TOKEN:-}"
|
| 86 |
|
| 87 |
# ----------------------------------------------------------------
|
| 88 |
+
# Setup
|
| 89 |
# ----------------------------------------------------------------
|
| 90 |
log "Running setup..."
|
| 91 |
node /app/spaces/huggingface/setup-hf-config.mjs || true
|
| 92 |
log "Setup done."
|
| 93 |
|
|
|
|
|
|
|
|
|
|
| 94 |
if [ -f /app/security-check.sh ]; then
|
| 95 |
sh /app/security-check.sh || true
|
| 96 |
fi
|
| 97 |
|
| 98 |
# ----------------------------------------------------------------
|
| 99 |
+
# Device auto-pairing (background)
|
| 100 |
# ----------------------------------------------------------------
|
| 101 |
(
|
| 102 |
DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
|
|
|
|
| 131 |
fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
|
| 132 |
fs.writeFileSync(pend, '[]');
|
| 133 |
console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
|
| 134 |
+
} catch(e) {}
|
| 135 |
JSEOF
|
| 136 |
fi
|
| 137 |
done
|
| 138 |
) &
|
| 139 |
|
| 140 |
# ----------------------------------------------------------------
|
| 141 |
+
# Gateway loop — uses new binary path
|
| 142 |
# ----------------------------------------------------------------
|
| 143 |
log "Starting gateway loop..."
|
| 144 |
+
log "Using OpenClaw binary: $OPENCLAW_BIN"
|
| 145 |
|
| 146 |
while true; do
|
| 147 |
log "Gateway starting..."
|
| 148 |
|
| 149 |
+
node "$OPENCLAW_BIN" gateway \
|
| 150 |
--allow-unconfigured \
|
| 151 |
--bind lan \
|
| 152 |
--port 7860
|
|
|
|
| 157 |
WAITED=0
|
| 158 |
while nc -z 127.0.0.1 7860 2>/dev/null; do
|
| 159 |
if [ $WAITED -eq 0 ]; then
|
| 160 |
+
log "Port 7860 still held - waiting..."
|
| 161 |
fi
|
| 162 |
sleep 2
|
| 163 |
WAITED=$((WAITED + 2))
|