Update entrypoint.sh
Browse files- entrypoint.sh +37 -2
entrypoint.sh
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
#!/bin/sh
|
|
|
|
| 2 |
# OpenClaw HF Spaces - Production Entrypoint
|
| 3 |
# Storage: HF Storage Bucket at /data (100 GB persistent)
|
| 4 |
|
|
@@ -96,12 +97,46 @@ for f in "$OPENCLAW_HOME"/.openclaw/telegram/update-offset-*.json \
|
|
| 96 |
fi
|
| 97 |
done
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
log "Running openclaw doctor --fix (state migration)..."
|
| 100 |
timeout 300 openclaw doctor --fix --non-interactive </dev/null \
|
| 101 |
-
||
|
| 102 |
-
|| warn "openclaw doctor failed - gateway may refuse to start"
|
| 103 |
log "Doctor step done."
|
| 104 |
|
|
|
|
|
|
|
|
|
|
| 105 |
# ----------------------------------------------------------------
|
| 106 |
# Auto-approve pending device pairings (background)
|
| 107 |
# ----------------------------------------------------------------
|
|
|
|
| 1 |
#!/bin/sh
|
| 2 |
+
umask 022
|
| 3 |
# OpenClaw HF Spaces - Production Entrypoint
|
| 4 |
# Storage: HF Storage Bucket at /data (100 GB persistent)
|
| 5 |
|
|
|
|
| 97 |
fi
|
| 98 |
done
|
| 99 |
|
| 100 |
+
# ---- Check shared state DB; restore from doctor's own backup if corrupt ----
|
| 101 |
+
check_db() {
|
| 102 |
+
DBPATH="$1" node - <<'JSEOF'
|
| 103 |
+
const { DatabaseSync } = require('node:sqlite');
|
| 104 |
+
try {
|
| 105 |
+
const db = new DatabaseSync(process.env.DBPATH, { readOnly: true });
|
| 106 |
+
const row = db.prepare('PRAGMA integrity_check').get();
|
| 107 |
+
db.close();
|
| 108 |
+
process.exit(Object.values(row)[0] === 'ok' ? 0 : 1);
|
| 109 |
+
} catch (e) {
|
| 110 |
+
console.error('[db-check] ' + e.message);
|
| 111 |
+
process.exit(1);
|
| 112 |
+
}
|
| 113 |
+
JSEOF
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
STATE_DB="$OPENCLAW_HOME/.openclaw/state/openclaw.sqlite"
|
| 117 |
+
if [ -f "$STATE_DB" ] && ! check_db "$STATE_DB" 2>/dev/null; then
|
| 118 |
+
warn "State DB failed integrity check - looking for an intact backup..."
|
| 119 |
+
GOOD=""
|
| 120 |
+
for B in $(ls -t "$STATE_DB".pre-startup-migration-*.bak 2>/dev/null); do
|
| 121 |
+
if check_db "$B" 2>/dev/null; then GOOD="$B"; break; fi
|
| 122 |
+
done
|
| 123 |
+
if [ -n "$GOOD" ]; then
|
| 124 |
+
mv "$STATE_DB" "$STATE_DB.corrupt-$(date +%s)"
|
| 125 |
+
rm -f "$STATE_DB-wal" "$STATE_DB-shm"
|
| 126 |
+
cp "$GOOD" "$STATE_DB" && log "Restored state DB from $GOOD"
|
| 127 |
+
else
|
| 128 |
+
warn "No intact backup found - leaving DB untouched"
|
| 129 |
+
fi
|
| 130 |
+
fi
|
| 131 |
+
|
| 132 |
log "Running openclaw doctor --fix (state migration)..."
|
| 133 |
timeout 300 openclaw doctor --fix --non-interactive </dev/null \
|
| 134 |
+
|| warn "openclaw doctor reported problems (see output above)"
|
|
|
|
| 135 |
log "Doctor step done."
|
| 136 |
|
| 137 |
+
# Plugins must not be world-writable or OpenClaw blocks them
|
| 138 |
+
chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
|
| 139 |
+
|
| 140 |
# ----------------------------------------------------------------
|
| 141 |
# Auto-approve pending device pairings (background)
|
| 142 |
# ----------------------------------------------------------------
|