Elysiadev11 commited on
Commit
fb5276a
Β·
verified Β·
1 Parent(s): 9ed6b0b

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +33 -22
start-openclaw.sh CHANGED
@@ -1,14 +1,18 @@
1
  #!/bin/bash
2
 
3
  # ─────────────────────────────────────────────────────────────
4
- # πŸ“ PATH: start-openclaw.sh (root HF Space repo)
5
  # ─────────────────────────────────────────────────────────────
6
 
7
  set +e
8
 
9
  echo "===== OpenClaw Startup ====="
10
 
11
- # ── 1. Direktori ───────────────────────────────────────────────
 
 
 
 
12
  mkdir -p /root/.openclaw/agents/main/sessions
13
  mkdir -p /root/.openclaw/credentials
14
  mkdir -p /root/.openclaw/sessions
@@ -19,37 +23,38 @@ echo ">>> Directories ready."
19
  python3 /app/sync.py restore
20
  echo ">>> Restore done."
21
 
22
- # ── 3. Fix DNS & Hosts (TELEGRAM FIX) ─────────────────────────
23
  echo "nameserver 1.1.1.1" >> /etc/resolv.conf
24
  echo "nameserver 8.8.8.8" >> /etc/resolv.conf
25
  echo "nameserver 8.8.4.4" >> /etc/resolv.conf
26
  echo "149.154.166.110 api.telegram.org" >> /etc/hosts
27
  echo ">>> DNS and Hosts fixed for Telegram."
28
 
29
- # ── 4. Chromium ───────────────────────────────────────────────
30
  export PLAYWRIGHT_BROWSERS_PATH=/root/.openclaw/browsers
31
  CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
32
 
33
  if [ -z "$CHROMIUM_PATH" ]; then
34
- echo ">>> Installing Chromium..."
35
- OPENCLAW_NM=$(npm root -g 2>/dev/null)/openclaw/node_modules/playwright-core/cli.js
36
- if timeout 180 node "$OPENCLAW_NM" install chromium; then
37
- echo ">>> Chromium OK"
38
- else
39
- echo ">>> WARN: Chromium install failed"
40
- fi
41
- CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
42
  else
43
- echo ">>> Chromium found: $CHROMIUM_PATH"
44
  fi
45
 
46
- # ── 5. Bersihkan OPENAI_API_BASE ──────────────────────────────
47
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
48
  | sed "s|/chat/completions||g" \
49
  | sed "s|/v1/|/v1|g" \
50
  | sed "s|/v1$|/v1|g")
51
 
52
  # ── 6. Generate openclaw.json ─────────────────────────────────
 
53
  cat > /root/.openclaw/openclaw.json <<EOF
54
  {
55
  "models": {
@@ -130,7 +135,7 @@ cat > /root/.openclaw/openclaw.json <<EOF
130
  }
131
  }
132
  EOF
133
- echo ">>> openclaw.json generated with User ID Allowlist and Browser requirePairing: false."
134
 
135
  # ── 7. Node.js reverse proxy (ANTI-TIMEOUT TRICK) ─────────────
136
  node -e "
@@ -149,8 +154,8 @@ function proxyHttp(req, res, targetPort) {
149
  res.writeHead(r.statusCode, r.headers);
150
  r.pipe(res, { end: true });
151
  });
152
-
153
- pr.on('error', (e) => {
154
  res.writeHead(200, { 'Content-Type': 'text/html' });
155
  res.end('<html style=\"background:#1e1e2e; color:#cdd6f4; font-family:sans-serif; text-align:center; padding-top:20%;\"><body><h2>πŸš€ OpenClaw is warming up...</h2><p>Hugging Face is downloading dependencies. Please refresh in a few seconds.</p></body></html>');
156
  });
@@ -188,12 +193,18 @@ server.listen(7860, '0.0.0.0', () => {
188
  " &
189
  echo ">>> Node.js WebSocket proxy started on port 7860."
190
 
191
- # ── 8. Backup otomatis setiap 1 jam ──────────────────────────
192
- (while true; do
193
- sleep 3600
194
- echo ">>> Running scheduled backup..."
195
  python3 /app/sync.py backup
196
- done) &
 
 
 
 
 
 
197
 
198
  # ── 9. Jalankan OpenClaw ──────────────────────────────────────
199
  echo ">>> Running openclaw doctor --fix..."
 
1
  #!/bin/bash
2
 
3
  # ─────────────────────────────────────────────────────────────
4
+ # πŸ“ PATH: start-openclaw.sh (root HF Space repo)
5
  # ─────────────────────────────────────────────────────────────
6
 
7
  set +e
8
 
9
  echo "===== OpenClaw Startup ====="
10
 
11
+ # ── TRAP: Backup saat container mati ─────────────────────────
12
+ # Kalau HF Spaces kill container (restart/idle), backup jalan dulu
13
+ trap 'echo ">>> [TRAP] Container stopping β€” final backup..."; python3 /app/sync.py backup; echo ">>> [TRAP] Done."' EXIT SIGTERM SIGINT
14
+
15
+ # ── 1. Direktori ──────────────────────────────────────────────
16
  mkdir -p /root/.openclaw/agents/main/sessions
17
  mkdir -p /root/.openclaw/credentials
18
  mkdir -p /root/.openclaw/sessions
 
23
  python3 /app/sync.py restore
24
  echo ">>> Restore done."
25
 
26
+ # ── 3. Fix DNS & Hosts (TELEGRAM FIX) ────────────────────────
27
  echo "nameserver 1.1.1.1" >> /etc/resolv.conf
28
  echo "nameserver 8.8.8.8" >> /etc/resolv.conf
29
  echo "nameserver 8.8.4.4" >> /etc/resolv.conf
30
  echo "149.154.166.110 api.telegram.org" >> /etc/hosts
31
  echo ">>> DNS and Hosts fixed for Telegram."
32
 
33
+ # ── 4. Chromium ──────────────────────────────────────────────
34
  export PLAYWRIGHT_BROWSERS_PATH=/root/.openclaw/browsers
35
  CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
36
 
37
  if [ -z "$CHROMIUM_PATH" ]; then
38
+ echo ">>> Installing Chromium..."
39
+ OPENCLAW_NM=$(npm root -g 2>/dev/null)/openclaw/node_modules/playwright-core/cli.js
40
+ if timeout 180 node "$OPENCLAW_NM" install chromium; then
41
+ echo ">>> Chromium OK"
42
+ else
43
+ echo ">>> WARN: Chromium install failed"
44
+ fi
45
+ CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
46
  else
47
+ echo ">>> Chromium found: $CHROMIUM_PATH"
48
  fi
49
 
50
+ # ── 5. Bersihkan OPENAI_API_BASE ─────────────────────────────
51
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
52
  | sed "s|/chat/completions||g" \
53
  | sed "s|/v1/|/v1|g" \
54
  | sed "s|/v1$|/v1|g")
55
 
56
  # ── 6. Generate openclaw.json ─────────────────────────────────
57
+ # openclaw.json selalu di-generate ulang dari env vars (tidak di-backup)
58
  cat > /root/.openclaw/openclaw.json <<EOF
59
  {
60
  "models": {
 
135
  }
136
  }
137
  EOF
138
+ echo ">>> openclaw.json generated."
139
 
140
  # ── 7. Node.js reverse proxy (ANTI-TIMEOUT TRICK) ─────────────
141
  node -e "
 
154
  res.writeHead(r.statusCode, r.headers);
155
  r.pipe(res, { end: true });
156
  });
157
+
158
+ pr.on('error', (e) => {
159
  res.writeHead(200, { 'Content-Type': 'text/html' });
160
  res.end('<html style=\"background:#1e1e2e; color:#cdd6f4; font-family:sans-serif; text-align:center; padding-top:20%;\"><body><h2>πŸš€ OpenClaw is warming up...</h2><p>Hugging Face is downloading dependencies. Please refresh in a few seconds.</p></body></html>');
161
  });
 
193
  " &
194
  echo ">>> Node.js WebSocket proxy started on port 7860."
195
 
196
+ # ── 8. Backup otomatis setiap 5 menit ────────────────────────
197
+ (
198
+ sleep 30
199
+ echo ">>> Initial backup (30s after startup)..."
200
  python3 /app/sync.py backup
201
+
202
+ while true; do
203
+ sleep 300
204
+ echo ">>> Scheduled backup..."
205
+ python3 /app/sync.py backup
206
+ done
207
+ ) &
208
 
209
  # ── 9. Jalankan OpenClaw ──────────────────────────────────────
210
  echo ">>> Running openclaw doctor --fix..."