Elysiadev11 commited on
Commit
a99ac07
Β·
verified Β·
1 Parent(s): b69a3ea

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +81 -36
start-openclaw.sh CHANGED
@@ -2,51 +2,57 @@
2
 
3
  # ─────────────────────────────────────────────────────────────
4
  # πŸ“ PATH: start-openclaw.sh (root HF Space repo)
5
- # Upload/edit file ini di:
6
- # https://huggingface.co/spaces/mark421/OpenClaw-ai/blob/main/start-openclaw.sh
7
  # ─────────────────────────────────────────────────────────────
8
 
9
- set -e
10
 
11
- # ── 1. Buat direktori yang dibutuhkan ──────────────────────────
 
 
12
  mkdir -p /root/.openclaw/agents/main/sessions
13
  mkdir -p /root/.openclaw/credentials
14
  mkdir -p /root/.openclaw/sessions
15
  mkdir -p /root/.openclaw/browsers
 
16
 
17
- # ── 2. Restore backup dari HF Dataset (kalau ada) ─────────────
18
  python3 /app/sync.py restore
 
19
 
20
-
21
- # ── DNS Fix untuk Chromium di Docker ─────────────────────────
22
- # HF Spaces Docker kadang DNS-nya tidak resolve dari Chromium
23
  echo "nameserver 8.8.8.8" >> /etc/resolv.conf
24
  echo "nameserver 8.8.4.4" >> /etc/resolv.conf
25
  echo ">>> DNS fixed."
26
- # ── 3. Install Playwright Chromium pakai CLI bawaan OpenClaw ──
27
- # (bukan python playwright β€” harus pakai node_modules openclaw)
28
- export PLAYWRIGHT_BROWSERS_PATH=/root/.openclaw/browsers
29
 
 
 
 
 
 
 
30
  CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
31
 
32
  if [ -z "$CHROMIUM_PATH" ]; then
33
- echo ">>> Chromium not found in backup, installing..."
34
- node $(npm root -g)/openclaw/node_modules/playwright-core/cli.js install chromium || \
35
- node /usr/local/lib/node_modules/openclaw/node_modules/playwright-core/cli.js install chromium || true
 
 
 
 
 
 
36
  CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
37
  else
38
- echo ">>> Chromium restored from backup: $CHROMIUM_PATH"
39
  fi
40
 
41
- echo ">>> Chromium path: $CHROMIUM_PATH"
42
-
43
- # ── 4. Bersihkan OPENAI_API_BASE ──────────────────────────────
44
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
45
  | sed "s|/chat/completions||g" \
46
  | sed "s|/v1/|/v1|g" \
47
  | sed "s|/v1$|/v1|g")
48
 
49
- # ── 5. Generate openclaw.json ──────────────────────────────────
50
  cat > /root/.openclaw/openclaw.json <<EOF
51
  {
52
  "models": {
@@ -63,12 +69,26 @@ cat > /root/.openclaw/openclaw.json <<EOF
63
  },
64
  "agents": {
65
  "defaults": {
66
- "model": { "primary": "nvidia/$MODEL" }
 
 
 
 
 
67
  }
68
  },
69
- "commands": {
70
- "restart": true
 
 
 
 
 
 
 
 
71
  },
 
72
  "browser": {
73
  "enabled": true,
74
  "headless": true,
@@ -83,19 +103,18 @@ cat > /root/.openclaw/openclaw.json <<EOF
83
  ],
84
  "executablePath": "$CHROMIUM_PATH",
85
  "defaultProfile": "openclaw",
86
- "ssrfPolicy": {
87
- "dangerouslyAllowPrivateNetwork": true
88
- },
89
  "profiles": {
90
  "openclaw": {
91
- "cdpPort": 18800
 
92
  }
93
  }
94
  },
95
  "gateway": {
96
  "mode": "local",
97
  "bind": "lan",
98
- "port": $PORT,
99
  "trustedProxies": ["0.0.0.0/0"],
100
  "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
101
  "http": {
@@ -112,17 +131,43 @@ cat > /root/.openclaw/openclaw.json <<EOF
112
  }
113
  }
114
  EOF
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
- echo ">>> openclaw.json generated."
 
117
 
118
- # ── 6. Backup otomatis setiap 1 jam ───────────────────────────
119
- (while true; do
120
- sleep 3600
121
- echo ">>> Running scheduled backup..."
122
- python3 /app/sync.py backup
123
- done) &
124
 
125
- # ── 7. Jalankan OpenClaw ───────────────────────────────────────
 
126
  openclaw doctor --fix
127
 
128
- exec openclaw gateway run --port $PORT
 
 
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
15
  mkdir -p /root/.openclaw/browsers
16
+ echo ">>> Directories ready."
17
 
18
+ # ── 2. Restore backup ─────────────────────────────────────────
19
  python3 /app/sync.py restore
20
+ echo ">>> Restore done."
21
 
22
+ # ── 3. Fix DNS ────────────────────────────────────────────────
 
 
23
  echo "nameserver 8.8.8.8" >> /etc/resolv.conf
24
  echo "nameserver 8.8.4.4" >> /etc/resolv.conf
25
  echo ">>> DNS fixed."
 
 
 
26
 
27
+ # ── 4. Install nginx ──────────────────────────────────────────
28
+ apt-get install -y --no-install-recommends nginx > /dev/null 2>&1
29
+ echo ">>> nginx installed."
30
+
31
+ # ── 5. Chromium ───────────────────────────────────────────────
32
+ export PLAYWRIGHT_BROWSERS_PATH=/root/.openclaw/browsers
33
  CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
34
 
35
  if [ -z "$CHROMIUM_PATH" ]; then
36
+ echo ">>> Installing Chromium..."
37
+ OPENCLAW_NM=$(npm root -g 2>/dev/null)/openclaw/node_modules/playwright-core/cli.js
38
+ if timeout 180 node "$OPENCLAW_NM" install chromium; then
39
+ echo ">>> Chromium OK (npm global)"
40
+ elif timeout 180 node /usr/local/lib/node_modules/openclaw/node_modules/playwright-core/cli.js install chromium; then
41
+ echo ">>> Chromium OK (local)"
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
+ # ── 6. Generate openclaw.json (OpenClaw di port 7862) ─────────
 
 
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
  cat > /root/.openclaw/openclaw.json <<EOF
57
  {
58
  "models": {
 
69
  },
70
  "agents": {
71
  "defaults": {
72
+ "model": { "primary": "nvidia/$MODEL" },
73
+ "tools": {
74
+ "fetch": { "enabled": true },
75
+ "computer": { "enabled": true },
76
+ "browser": { "enabled": true }
77
+ }
78
  }
79
  },
80
+ "channels": {
81
+ "telegram": {
82
+ "enabled": true,
83
+ "botToken": "$TELEGRAM_BOT_TOKEN",
84
+ "dmPolicy": "open",
85
+ "webhookUrl": "https://mark421-openclaw-ai.hf.space/telegram/webhook",
86
+ "webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
87
+ "webhookHost": "0.0.0.0",
88
+ "webhookPort": 8787
89
+ }
90
  },
91
+ "commands": { "restart": true },
92
  "browser": {
93
  "enabled": true,
94
  "headless": true,
 
103
  ],
104
  "executablePath": "$CHROMIUM_PATH",
105
  "defaultProfile": "openclaw",
106
+ "ssrfPolicy": { "dangerouslyAllowPrivateNetwork": true },
 
 
107
  "profiles": {
108
  "openclaw": {
109
+ "cdpPort": 18800,
110
+ "color": "0088FF"
111
  }
112
  }
113
  },
114
  "gateway": {
115
  "mode": "local",
116
  "bind": "lan",
117
+ "port": 7862,
118
  "trustedProxies": ["0.0.0.0/0"],
119
  "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
120
  "http": {
 
131
  }
132
  }
133
  EOF
134
+ echo ">>> openclaw.json generated (OpenClaw on port 7862)."
135
+
136
+ # ── 7. Nginx config β€” reverse proxy di port 7860 ──────────────
137
+ cat > /etc/nginx/nginx.conf <<'NGINXCONF'
138
+ events { worker_connections 1024; }
139
+ http {
140
+ server {
141
+ listen 7860;
142
+
143
+ # Telegram webhook native OpenClaw β†’ port 8787
144
+ location /telegram/webhook {
145
+ proxy_pass http://localhost:8787;
146
+ proxy_set_header Host $host;
147
+ proxy_read_timeout 30s;
148
+ }
149
+
150
+ # Semua traffic lain β†’ OpenClaw gateway
151
+ location / {
152
+ proxy_pass http://localhost:7862;
153
+ proxy_set_header Host $host;
154
+ proxy_set_header X-Real-IP $remote_addr;
155
+ proxy_read_timeout 300s;
156
+ proxy_buffering off;
157
+ }
158
+ }
159
+ }
160
+ NGINXCONF
161
 
162
+ nginx
163
+ echo ">>> nginx started on port 7860."
164
 
165
+ # ── 8. Backup otomatis setiap 1 jam ──────────────────────────
166
+ (while true; do sleep 3600; python3 /app/sync.py backup; done) &
 
 
 
 
167
 
168
+ # ── 9. Jalankan OpenClaw di port 7862 ────────────────────────
169
+ echo ">>> Running openclaw doctor --fix..."
170
  openclaw doctor --fix
171
 
172
+ echo ">>> Starting OpenClaw on port 7862..."
173
+ exec openclaw gateway run --port 7862