Subsequently commited on
Commit
42df02b
·
verified ·
1 Parent(s): 67916a7

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +66 -19
entrypoint.sh CHANGED
@@ -1,9 +1,8 @@
1
  #!/bin/sh
2
- umask 022
3
  # OpenClaw HF Spaces - Production Entrypoint
4
- # Storage: HF Storage Bucket at /data (100 GB persistent)
5
 
6
- # ── Fix: Force IPv4 for Telegram (IPv6 route broken on HF nodes) ──
7
  sysctl -w net.ipv6.conf.all.disable_ipv6=1 2>/dev/null || true
8
  sysctl -w net.ipv6.conf.default.disable_ipv6=1 2>/dev/null || true
9
  export NODE_OPTIONS="--dns-result-order=ipv4first ${NODE_OPTIONS:-}"
@@ -83,21 +82,10 @@ if [ -f /app/security-check.sh ]; then
83
  fi
84
 
85
  # ----------------------------------------------------------------
86
- # Migrate legacy state from older OpenClaw versions (required by new releases)
87
  # ----------------------------------------------------------------
88
- # Move retired Telegram JSON state aside (it blocks doctor migration;
89
- # only holds update offsets / sent-message cache). Kept as backup.
90
- LEGACY_BAK="$OPENCLAW_HOME/legacy-telegram-backup"
91
- mkdir -p "$LEGACY_BAK"
92
- for f in "$OPENCLAW_HOME"/.openclaw/telegram/update-offset-*.json \
93
- "$OPENCLAW_HOME"/.openclaw/agents/*/sessions/sessions.json.telegram-sent-messages.json; do
94
- if [ -f "$f" ]; then
95
- mv "$f" "$LEGACY_BAK/$(echo "$f" | tr '/' '_')" \
96
- && log "Moved legacy telegram state: $f"
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');
@@ -113,7 +101,35 @@ try {
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=""
@@ -129,9 +145,40 @@ if [ -f "$STATE_DB" ] && ! check_db "$STATE_DB" 2>/dev/null; then
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
 
1
  #!/bin/sh
 
2
  # OpenClaw HF Spaces - Production Entrypoint
3
+ umask 022
4
 
5
+ # ── Force IPv4 for Telegram (IPv6 route broken on HF nodes) ──
6
  sysctl -w net.ipv6.conf.all.disable_ipv6=1 2>/dev/null || true
7
  sysctl -w net.ipv6.conf.default.disable_ipv6=1 2>/dev/null || true
8
  export NODE_OPTIONS="--dns-result-order=ipv4first ${NODE_OPTIONS:-}"
 
82
  fi
83
 
84
  # ----------------------------------------------------------------
85
+ # State DB helpers
86
  # ----------------------------------------------------------------
87
+ STATE_DB="$OPENCLAW_HOME/.openclaw/state/openclaw.sqlite"
 
 
 
 
 
 
 
 
 
 
88
 
 
89
  check_db() {
90
  DBPATH="$1" node - <<'JSEOF'
91
  const { DatabaseSync } = require('node:sqlite');
 
101
  JSEOF
102
  }
103
 
104
+ dump_owner() {
105
+ DBPATH="$1" node - <<'JSEOF'
106
+ const { DatabaseSync } = require('node:sqlite');
107
+ try {
108
+ const db = new DatabaseSync(process.env.DBPATH, { readOnly: true });
109
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND (name LIKE '%owner%' OR name LIKE '%lock%' OR name LIKE '%lease%' OR name LIKE '%heartbeat%' OR name LIKE '%machine_state%')").all();
110
+ for (const t of tables) {
111
+ console.log('[owner-dump] table ' + t.name);
112
+ for (const r of db.prepare('SELECT * FROM "' + t.name + '" LIMIT 5').all()) {
113
+ console.log('[owner-dump] ' + JSON.stringify(r).slice(0, 400));
114
+ }
115
+ }
116
+ db.close();
117
+ } catch (e) { console.log('[owner-dump] ' + e.message); }
118
+ JSEOF
119
+ }
120
+
121
+ # Move retired Telegram JSON state aside (blocks doctor migration; kept as backup)
122
+ LEGACY_BAK="$OPENCLAW_HOME/legacy-telegram-backup"
123
+ mkdir -p "$LEGACY_BAK"
124
+ for f in "$OPENCLAW_HOME"/.openclaw/telegram/update-offset-*.json \
125
+ "$OPENCLAW_HOME"/.openclaw/agents/*/sessions/sessions.json.telegram-sent-messages.json; do
126
+ if [ -f "$f" ]; then
127
+ mv "$f" "$LEGACY_BAK/$(echo "$f" | tr '/' '_')" \
128
+ && log "Moved legacy telegram state: $f"
129
+ fi
130
+ done
131
+
132
+ # If the state DB is corrupt, restore from doctor's own pre-migration backup
133
  if [ -f "$STATE_DB" ] && ! check_db "$STATE_DB" 2>/dev/null; then
134
  warn "State DB failed integrity check - looking for an intact backup..."
135
  GOOD=""
 
145
  fi
146
  fi
147
 
148
+ # ----------------------------------------------------------------
149
+ # Doctor (state migration) with lock diagnostics and one-time fallback
150
+ # ----------------------------------------------------------------
151
+ run_doctor() {
152
+ timeout 300 openclaw doctor --fix --non-interactive </dev/null >/tmp/doctor.out 2>&1
153
+ cat /tmp/doctor.out
154
+ }
155
+ doctor_locked() {
156
+ grep -q "could not enter maintenance" /tmp/doctor.out
157
+ }
158
+
159
  log "Running openclaw doctor --fix (state migration)..."
160
+ run_doctor
161
+ if doctor_locked; then
162
+ warn "doctor blocked by state ownership lock - diagnostics follow"
163
+ log "now (UTC): $(date -u +%Y-%m-%dT%H:%M:%S)"
164
+ dump_owner "$STATE_DB" 2>/dev/null
165
+ find "$OPENCLAW_HOME/.openclaw" -maxdepth 3 -iname '*lock*' 2>/dev/null | head -n 20
166
+ warn "retrying doctor in 30s..."
167
+ sleep 30
168
+ run_doctor
169
+ fi
170
+ if doctor_locked; then
171
+ if ls "$STATE_DB".locked-* >/dev/null 2>&1; then
172
+ warn "still locked, and the one-time fallback was already used - not touching the DB again"
173
+ else
174
+ warn "still locked - moving state DB aside (one time) and retrying on a fresh DB"
175
+ TSX=$(date +%s)
176
+ for f in "$STATE_DB" "$STATE_DB-wal" "$STATE_DB-shm"; do
177
+ [ -e "$f" ] && mv "$f" "$f.locked-$TSX"
178
+ done
179
+ run_doctor
180
+ fi
181
+ fi
182
  log "Doctor step done."
183
 
184
  # Plugins must not be world-writable or OpenClaw blocks them