Elysiadev11 commited on
Commit
faffa9c
Β·
verified Β·
1 Parent(s): eab571d

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +59 -10
start-openclaw.sh CHANGED
@@ -48,9 +48,6 @@ CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
48
  | sed "s|/v1$|/v1|g")
49
 
50
  # ── 6. Generate openclaw.json ─────────────────────────────────
51
- # OpenClaw langsung di port $PORT (7860) β€” tidak perlu proxy
52
- # Telegram webhook juga di-handle native oleh OpenClaw di port 8787
53
- # tapi OpenClaw register webhook ke URL publik HF Spaces
54
  cat > /root/.openclaw/openclaw.json <<EOF
55
  {
56
  "models": {
@@ -105,14 +102,14 @@ cat > /root/.openclaw/openclaw.json <<EOF
105
  "webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
106
  "webhookPath": "/telegram/webhook",
107
  "webhookHost": "0.0.0.0",
108
- "webhookPort": $PORT,
109
  "streaming": "off"
110
  }
111
  },
112
  "gateway": {
113
  "mode": "local",
114
  "bind": "lan",
115
- "port": $PORT,
116
  "trustedProxies": ["0.0.0.0/0"],
117
  "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
118
  "http": {
@@ -129,18 +126,70 @@ cat > /root/.openclaw/openclaw.json <<EOF
129
  }
130
  }
131
  EOF
132
- echo ">>> openclaw.json generated with Primary and Fallback setup."
133
 
134
- # ── 7. Backup otomatis setiap 1 jam ──────────────────────────
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  (while true; do
136
  sleep 3600
137
  echo ">>> Running scheduled backup..."
138
  python3 /app/sync.py backup
139
  done) &
140
 
141
- # ── 8. Jalankan OpenClaw ──────────────────────────────────────
142
  echo ">>> Running openclaw doctor --fix..."
143
  openclaw doctor --fix
144
 
145
- echo ">>> Starting OpenClaw on port $PORT..."
146
- exec openclaw gateway run --port $PORT
 
48
  | sed "s|/v1$|/v1|g")
49
 
50
  # ── 6. Generate openclaw.json ─────────────────────────────────
 
 
 
51
  cat > /root/.openclaw/openclaw.json <<EOF
52
  {
53
  "models": {
 
102
  "webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
103
  "webhookPath": "/telegram/webhook",
104
  "webhookHost": "0.0.0.0",
105
+ "webhookPort": 8787,
106
  "streaming": "off"
107
  }
108
  },
109
  "gateway": {
110
  "mode": "local",
111
  "bind": "lan",
112
+ "port": 7862,
113
  "trustedProxies": ["0.0.0.0/0"],
114
  "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
115
  "http": {
 
126
  }
127
  }
128
  EOF
129
+ echo ">>> openclaw.json generated with Primary, Fallback, and split ports."
130
 
131
+ # ── 7. Node.js reverse proxy di port 7860 ─────────────────────
132
+ node -e "
133
+ const http = require('http');
134
+ const net = require('net');
135
+
136
+ function proxyHttp(req, res, targetPort) {
137
+ const opts = {
138
+ hostname: '127.0.0.1', port: targetPort,
139
+ path: req.url, method: req.method,
140
+ headers: req.headers,
141
+ };
142
+ const pr = http.request(opts, (r) => {
143
+ res.writeHead(r.statusCode, r.headers);
144
+ r.pipe(res, { end: true });
145
+ });
146
+ pr.on('error', (e) => { res.writeHead(502); res.end('Bad gateway: ' + e.message); });
147
+ req.pipe(pr, { end: true });
148
+ }
149
+
150
+ function proxyWs(req, socket, head, targetPort) {
151
+ const conn = net.connect(targetPort, '127.0.0.1', () => {
152
+ conn.write(
153
+ 'GET ' + req.url + ' HTTP/1.1\r\n' +
154
+ Object.entries(req.headers).map(([k,v]) => k+': '+v).join('\r\n') +
155
+ '\r\n\r\n'
156
+ );
157
+ if (head && head.length) conn.write(head);
158
+ socket.pipe(conn);
159
+ conn.pipe(socket);
160
+ });
161
+ conn.on('error', (e) => { console.error('WS proxy error:', e.message); socket.destroy(); });
162
+ socket.on('error', () => conn.destroy());
163
+ }
164
+
165
+ const server = http.createServer((req, res) => {
166
+ const port = req.url.startsWith('/telegram/webhook') ? 8787 : 7862;
167
+ proxyHttp(req, res, port);
168
+ });
169
+
170
+ server.on('upgrade', (req, socket, head) => {
171
+ const port = req.url.startsWith('/telegram/webhook') ? 8787 : 7862;
172
+ proxyWs(req, socket, head, port);
173
+ });
174
+
175
+ server.listen(7860, '0.0.0.0', () => {
176
+ console.log('Proxy (HTTP+WebSocket) on port 7860');
177
+ console.log(' /telegram/webhook β†’ :8787');
178
+ console.log(' /* (incl. WSS) β†’ :7862');
179
+ });
180
+ " &
181
+ echo ">>> Node.js WebSocket proxy started on port 7860."
182
+
183
+ # ── 8. Backup otomatis setiap 1 jam ──────────────────────────
184
  (while true; do
185
  sleep 3600
186
  echo ">>> Running scheduled backup..."
187
  python3 /app/sync.py backup
188
  done) &
189
 
190
+ # ── 9. Jalankan OpenClaw ──────────────────────────────────────
191
  echo ">>> Running openclaw doctor --fix..."
192
  openclaw doctor --fix
193
 
194
+ echo ">>> Starting OpenClaw on port 7862..."
195
+ exec openclaw gateway run --port 7862