Elysiadev11 commited on
Commit
f53effa
Β·
verified Β·
1 Parent(s): 9e70c57

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +66 -38
start-openclaw.sh CHANGED
@@ -19,10 +19,12 @@ echo ">>> Directories ready."
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. Chromium ───────────────────────────────────────────────
28
  export PLAYWRIGHT_BROWSERS_PATH=/root/.openclaw/browsers
@@ -48,13 +50,18 @@ CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
48
  | sed "s|/v1$|/v1|g")
49
 
50
  # ── 6. Generate openclaw.json ─────────────────────────────────
51
- # OpenClaw gateway di port 7862 (internal)
52
- # Telegram webhook listener di port 8787 (internal, OpenClaw native)
53
- # Node.js proxy di port 7860 (public HF Spaces) β€” route berdasarkan path
54
  cat > /root/.openclaw/openclaw.json <<EOF
55
  {
56
  "models": {
57
  "providers": {
 
 
 
 
 
 
 
 
58
  "nvidia": {
59
  "baseUrl": "$CLEAN_BASE",
60
  "apiKey": "$OPENAI_API_KEY",
@@ -67,12 +74,16 @@ cat > /root/.openclaw/openclaw.json <<EOF
67
  },
68
  "agents": {
69
  "defaults": {
70
- "model": { "primary": "nvidia/$MODEL" }
 
 
 
71
  }
72
  },
73
  "commands": { "restart": true },
74
  "browser": {
75
  "enabled": true,
 
76
  "headless": true,
77
  "noSandbox": true,
78
  "executablePath": "$CHROMIUM_PATH",
@@ -89,13 +100,14 @@ cat > /root/.openclaw/openclaw.json <<EOF
89
  "telegram": {
90
  "enabled": true,
91
  "botToken": "$TELEGRAM_BOT_TOKEN",
92
- "dmPolicy": "open",
 
93
  "webhookUrl": "https://elysiadev11-kimiclaw.hf.space/telegram/webhook",
94
  "webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
95
  "webhookPath": "/telegram/webhook",
96
  "webhookHost": "0.0.0.0",
97
  "webhookPort": 8787,
98
- "streaming": "none"
99
  }
100
  },
101
  "gateway": {
@@ -118,47 +130,63 @@ cat > /root/.openclaw/openclaw.json <<EOF
118
  }
119
  }
120
  EOF
121
- echo ">>> openclaw.json generated."
122
 
123
- # ── 7. Node.js reverse proxy di port 7860 ─────────────────────
124
- # Route /telegram/webhook β†’ OpenClaw webhook (8787)
125
- # Route semua lain β†’ OpenClaw gateway (7862)
126
  node -e "
127
  const http = require('http');
 
128
 
129
- function proxy(req, res, targetPort) {
130
- const options = {
131
- hostname: '127.0.0.1',
132
- port: targetPort,
133
- path: req.url,
134
- method: req.method,
135
  headers: req.headers,
136
  };
137
- const proxyReq = http.request(options, (proxyRes) => {
138
- res.writeHead(proxyRes.statusCode, proxyRes.headers);
139
- proxyRes.pipe(res, { end: true });
140
  });
141
- proxyReq.on('error', (e) => {
142
- console.error('Proxy error:', e.message);
143
- res.writeHead(502);
144
- res.end('Bad gateway');
145
  });
146
- req.pipe(proxyReq, { end: true });
147
  }
148
 
149
- http.createServer((req, res) => {
150
- if (req.url.startsWith('/telegram/webhook')) {
151
- proxy(req, res, 8787); // OpenClaw native Telegram webhook
152
- } else {
153
- proxy(req, res, 7862); // OpenClaw gateway UI + API
154
- }
155
- }).listen(7860, '0.0.0.0', () => {
156
- console.log('Proxy listening on port 7860');
157
- console.log(' /telegram/webhook β†’ localhost:8787 (OpenClaw Telegram)');
158
- console.log(' /* β†’ localhost:7862 (OpenClaw gateway)');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  });
160
  " &
161
- echo ">>> Node.js proxy started on port 7860."
162
 
163
  # ── 8. Backup otomatis setiap 1 jam ──────────────────────────
164
  (while true; do
@@ -167,7 +195,7 @@ echo ">>> Node.js proxy started on port 7860."
167
  python3 /app/sync.py backup
168
  done) &
169
 
170
- # ── 9. Jalankan OpenClaw di port 7862 ────────────────────────
171
  echo ">>> Running openclaw doctor --fix..."
172
  openclaw doctor --fix
173
 
 
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
 
50
  | sed "s|/v1$|/v1|g")
51
 
52
  # ── 6. Generate openclaw.json ─────────────────────────────────
 
 
 
53
  cat > /root/.openclaw/openclaw.json <<EOF
54
  {
55
  "models": {
56
  "providers": {
57
+ "kilo_gateway": {
58
+ "baseUrl": "https://api.kilo.ai/api/gateway",
59
+ "apiKey": "anonymous",
60
+ "api": "openai-completions",
61
+ "models": [
62
+ { "id": "kilo-auto/free", "name": "Kilo Auto Free", "contextWindow": 128000, "maxTokens": 16000 }
63
+ ]
64
+ },
65
  "nvidia": {
66
  "baseUrl": "$CLEAN_BASE",
67
  "apiKey": "$OPENAI_API_KEY",
 
74
  },
75
  "agents": {
76
  "defaults": {
77
+ "model": {
78
+ "primary": "kilo_gateway/kilo-auto/free",
79
+ "fallbacks": ["nvidia/$MODEL"]
80
+ }
81
  }
82
  },
83
  "commands": { "restart": true },
84
  "browser": {
85
  "enabled": true,
86
+ "requirePairing": false,
87
  "headless": true,
88
  "noSandbox": true,
89
  "executablePath": "$CHROMIUM_PATH",
 
100
  "telegram": {
101
  "enabled": true,
102
  "botToken": "$TELEGRAM_BOT_TOKEN",
103
+ "dmPolicy": "allowlist",
104
+ "allowFrom": ["$TELEGRAM_ALLOW_ID"],
105
  "webhookUrl": "https://elysiadev11-kimiclaw.hf.space/telegram/webhook",
106
  "webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
107
  "webhookPath": "/telegram/webhook",
108
  "webhookHost": "0.0.0.0",
109
  "webhookPort": 8787,
110
+ "streaming": "off"
111
  }
112
  },
113
  "gateway": {
 
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 "
137
  const http = require('http');
138
+ const net = require('net');
139
 
140
+ process.on('uncaughtException', err => console.error('Proxy Exception:', err.message));
141
+
142
+ function proxyHttp(req, res, targetPort) {
143
+ const opts = {
144
+ hostname: '127.0.0.1', port: targetPort,
145
+ path: req.url, method: req.method,
146
  headers: req.headers,
147
  };
148
+ const pr = http.request(opts, (r) => {
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
  });
157
+ req.pipe(pr, { end: true });
158
  }
159
 
160
+ function proxyWs(req, socket, head, targetPort) {
161
+ const conn = net.connect(targetPort, '127.0.0.1', () => {
162
+ conn.write(
163
+ 'GET ' + req.url + ' HTTP/1.1\r\n' +
164
+ Object.entries(req.headers).map(([k,v]) => k+': '+v).join('\r\n') +
165
+ '\r\n\r\n'
166
+ );
167
+ if (head && head.length) conn.write(head);
168
+ socket.pipe(conn);
169
+ conn.pipe(socket);
170
+ });
171
+ conn.on('error', (e) => { socket.destroy(); });
172
+ socket.on('error', () => conn.destroy());
173
+ }
174
+
175
+ const server = http.createServer((req, res) => {
176
+ const port = req.url.startsWith('/telegram/webhook') ? 8787 : 7862;
177
+ proxyHttp(req, res, port);
178
+ });
179
+
180
+ server.on('upgrade', (req, socket, head) => {
181
+ const port = req.url.startsWith('/telegram/webhook') ? 8787 : 7862;
182
+ proxyWs(req, socket, head, port);
183
+ });
184
+
185
+ server.listen(7860, '0.0.0.0', () => {
186
+ console.log('Proxy (HTTP+WebSocket) on port 7860 (Anti-Timeout Active)');
187
  });
188
  " &
189
+ echo ">>> Node.js WebSocket proxy started on port 7860."
190
 
191
  # ── 8. Backup otomatis setiap 1 jam ──────────────────────────
192
  (while true; do
 
195
  python3 /app/sync.py backup
196
  done) &
197
 
198
+ # ── 9. Jalankan OpenClaw ──────────────────────────────────────
199
  echo ">>> Running openclaw doctor --fix..."
200
  openclaw doctor --fix
201