Elysiadev11 commited on
Commit
a744254
Β·
verified Β·
1 Parent(s): f16d7f4

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +65 -63
start-openclaw.sh CHANGED
@@ -24,11 +24,7 @@ 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
 
@@ -36,9 +32,7 @@ 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
@@ -47,12 +41,16 @@ 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,23 +67,7 @@ cat > /root/.openclaw/openclaw.json <<EOF
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 },
@@ -93,14 +75,6 @@ cat > /root/.openclaw/openclaw.json <<EOF
93
  "enabled": true,
94
  "headless": true,
95
  "noSandbox": true,
96
- "chromiumArgs": [
97
- "--no-sandbox",
98
- "--disable-setuid-sandbox",
99
- "--disable-dev-shm-usage",
100
- "--disable-gpu",
101
- "--dns-prefetch-disable",
102
- "--ignore-certificate-errors"
103
- ],
104
  "executablePath": "$CHROMIUM_PATH",
105
  "defaultProfile": "openclaw",
106
  "ssrfPolicy": { "dangerouslyAllowPrivateNetwork": true },
@@ -111,6 +85,19 @@ cat > /root/.openclaw/openclaw.json <<EOF
111
  }
112
  }
113
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  "gateway": {
115
  "mode": "local",
116
  "bind": "lan",
@@ -131,39 +118,54 @@ cat > /root/.openclaw/openclaw.json <<EOF
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..."
 
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
29
  CHROMIUM_PATH=$(find /root/.openclaw/browsers -name "chrome" -type f 2>/dev/null | head -1)
30
 
 
32
  echo ">>> Installing Chromium..."
33
  OPENCLAW_NM=$(npm root -g 2>/dev/null)/openclaw/node_modules/playwright-core/cli.js
34
  if timeout 180 node "$OPENCLAW_NM" install chromium; then
35
+ echo ">>> Chromium OK"
 
 
36
  else
37
  echo ">>> WARN: Chromium install failed"
38
  fi
 
41
  echo ">>> Chromium found: $CHROMIUM_PATH"
42
  fi
43
 
44
+ # ── 5. Bersihkan OPENAI_API_BASE ──────────────────────────────
45
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
46
  | sed "s|/chat/completions||g" \
47
  | sed "s|/v1/|/v1|g" \
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": {
 
67
  },
68
  "agents": {
69
  "defaults": {
70
+ "model": { "primary": "nvidia/$MODEL" }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
  },
73
  "commands": { "restart": true },
 
75
  "enabled": true,
76
  "headless": true,
77
  "noSandbox": true,
 
 
 
 
 
 
 
 
78
  "executablePath": "$CHROMIUM_PATH",
79
  "defaultProfile": "openclaw",
80
  "ssrfPolicy": { "dangerouslyAllowPrivateNetwork": true },
 
85
  }
86
  }
87
  },
88
+ "channels": {
89
+ "telegram": {
90
+ "enabled": true,
91
+ "botToken": "$TELEGRAM_BOT_TOKEN",
92
+ "dmPolicy": "open",
93
+ "webhookUrl": "https://mark421-openclaw-ai.hf.space/telegram/webhook",
94
+ "webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
95
+ "webhookPath": "/telegram/webhook",
96
+ "webhookHost": "0.0.0.0",
97
+ "webhookPort": 8787,
98
+ "streaming": "partial"
99
+ }
100
+ },
101
  "gateway": {
102
  "mode": "local",
103
  "bind": "lan",
 
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
165
+ sleep 3600
166
+ echo ">>> Running scheduled backup..."
167
+ python3 /app/sync.py backup
168
+ done) &
169
 
170
  # ── 9. Jalankan OpenClaw di port 7862 ────────────────────────
171
  echo ">>> Running openclaw doctor --fix..."