Spaces:
Sleeping
Sleeping
Update start-openclaw.sh
Browse files- start-openclaw.sh +23 -70
start-openclaw.sh
CHANGED
|
@@ -48,13 +48,23 @@ CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
|
|
| 48 |
| sed "s|/v1$|/v1|g")
|
| 49 |
|
| 50 |
# ββ 6. Generate openclaw.json βββββββββββββββββββββββββββββββββ
|
| 51 |
-
# OpenClaw
|
| 52 |
-
# Telegram webhook
|
| 53 |
-
#
|
| 54 |
cat > /root/.openclaw/openclaw.json <<EOF
|
| 55 |
{
|
| 56 |
"models": {
|
| 57 |
"providers": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
"nvidia": {
|
| 59 |
"baseUrl": "$CLEAN_BASE",
|
| 60 |
"apiKey": "$OPENAI_API_KEY",
|
|
@@ -67,7 +77,10 @@ cat > /root/.openclaw/openclaw.json <<EOF
|
|
| 67 |
},
|
| 68 |
"agents": {
|
| 69 |
"defaults": {
|
| 70 |
-
"model": {
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
},
|
| 73 |
"commands": { "restart": true },
|
|
@@ -94,14 +107,14 @@ cat > /root/.openclaw/openclaw.json <<EOF
|
|
| 94 |
"webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
|
| 95 |
"webhookPath": "/telegram/webhook",
|
| 96 |
"webhookHost": "0.0.0.0",
|
| 97 |
-
"webhookPort":
|
| 98 |
"streaming": "none"
|
| 99 |
}
|
| 100 |
},
|
| 101 |
"gateway": {
|
| 102 |
"mode": "local",
|
| 103 |
"bind": "lan",
|
| 104 |
-
"port":
|
| 105 |
"trustedProxies": ["0.0.0.0/0"],
|
| 106 |
"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
|
| 107 |
"http": {
|
|
@@ -120,76 +133,16 @@ cat > /root/.openclaw/openclaw.json <<EOF
|
|
| 120 |
EOF
|
| 121 |
echo ">>> openclaw.json generated."
|
| 122 |
|
| 123 |
-
# ββ 7.
|
| 124 |
-
# PENTING: Harus support WebSocket upgrade β tanpa ini web UI 1006!
|
| 125 |
-
# Route /telegram/webhook β OpenClaw webhook (8787)
|
| 126 |
-
# Route semua lain (termasuk WSS) β OpenClaw gateway (7862)
|
| 127 |
-
node -e "
|
| 128 |
-
const http = require('http');
|
| 129 |
-
const net = require('net');
|
| 130 |
-
|
| 131 |
-
function proxyHttp(req, res, targetPort) {
|
| 132 |
-
const opts = {
|
| 133 |
-
hostname: '127.0.0.1', port: targetPort,
|
| 134 |
-
path: req.url, method: req.method,
|
| 135 |
-
headers: req.headers,
|
| 136 |
-
};
|
| 137 |
-
const pr = http.request(opts, (r) => {
|
| 138 |
-
res.writeHead(r.statusCode, r.headers);
|
| 139 |
-
r.pipe(res, { end: true });
|
| 140 |
-
});
|
| 141 |
-
pr.on('error', (e) => { res.writeHead(502); res.end('Bad gateway: ' + e.message); });
|
| 142 |
-
req.pipe(pr, { end: true });
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
function proxyWs(req, socket, head, targetPort) {
|
| 146 |
-
const conn = net.connect(targetPort, '127.0.0.1', () => {
|
| 147 |
-
conn.write(
|
| 148 |
-
'GET ' + req.url + ' HTTP/1.1
|
| 149 |
-
' +
|
| 150 |
-
Object.entries(req.headers).map(([k,v]) => k+': '+v).join('
|
| 151 |
-
') +
|
| 152 |
-
'
|
| 153 |
-
|
| 154 |
-
'
|
| 155 |
-
);
|
| 156 |
-
if (head && head.length) conn.write(head);
|
| 157 |
-
socket.pipe(conn);
|
| 158 |
-
conn.pipe(socket);
|
| 159 |
-
});
|
| 160 |
-
conn.on('error', (e) => { console.error('WS proxy error:', e.message); socket.destroy(); });
|
| 161 |
-
socket.on('error', () => conn.destroy());
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
const server = http.createServer((req, res) => {
|
| 165 |
-
const port = req.url.startsWith('/telegram/webhook') ? 8787 : 7862;
|
| 166 |
-
proxyHttp(req, res, port);
|
| 167 |
-
});
|
| 168 |
-
|
| 169 |
-
// WebSocket upgrade β wajib untuk OpenClaw Control UI
|
| 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 |
-
# ββ
|
| 191 |
echo ">>> Running openclaw doctor --fix..."
|
| 192 |
openclaw doctor --fix
|
| 193 |
|
| 194 |
-
echo ">>> Starting OpenClaw on port
|
| 195 |
-
exec openclaw gateway run --port
|
|
|
|
| 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": {
|
| 57 |
"providers": {
|
| 58 |
+
"kilo": {
|
| 59 |
+
"baseUrl": "https://api.kilo.ai/api/gateway",
|
| 60 |
+
"apiKey": "anonymous",
|
| 61 |
+
"api": "openai-completions",
|
| 62 |
+
"models": [
|
| 63 |
+
{ "id": "minimax/minimax-m2.1:free", "name": "MiniMax M2.1 Free", "contextWindow": 1000000 },
|
| 64 |
+
{ "id": "z-ai/glm-5:free", "name": "Z.AI GLM-5 Free", "contextWindow": 128000 },
|
| 65 |
+
{ "id": "moonshotai/kimi-k2.5:free", "name": "Kimi K2.5 Free", "contextWindow": 128000 }
|
| 66 |
+
]
|
| 67 |
+
},
|
| 68 |
"nvidia": {
|
| 69 |
"baseUrl": "$CLEAN_BASE",
|
| 70 |
"apiKey": "$OPENAI_API_KEY",
|
|
|
|
| 77 |
},
|
| 78 |
"agents": {
|
| 79 |
"defaults": {
|
| 80 |
+
"model": {
|
| 81 |
+
"primary": "kilo/z-ai/glm-5:free",
|
| 82 |
+
"fallback": "nvidia/$MODEL"
|
| 83 |
+
}
|
| 84 |
}
|
| 85 |
},
|
| 86 |
"commands": { "restart": true },
|
|
|
|
| 107 |
"webhookSecret": "$OPENCLAW_GATEWAY_PASSWORD",
|
| 108 |
"webhookPath": "/telegram/webhook",
|
| 109 |
"webhookHost": "0.0.0.0",
|
| 110 |
+
"webhookPort": $PORT,
|
| 111 |
"streaming": "none"
|
| 112 |
}
|
| 113 |
},
|
| 114 |
"gateway": {
|
| 115 |
"mode": "local",
|
| 116 |
"bind": "lan",
|
| 117 |
+
"port": $PORT,
|
| 118 |
"trustedProxies": ["0.0.0.0/0"],
|
| 119 |
"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
|
| 120 |
"http": {
|
|
|
|
| 133 |
EOF
|
| 134 |
echo ">>> openclaw.json generated."
|
| 135 |
|
| 136 |
+
# ββ 7. Backup otomatis setiap 1 jam ββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
(while true; do
|
| 138 |
sleep 3600
|
| 139 |
echo ">>> Running scheduled backup..."
|
| 140 |
python3 /app/sync.py backup
|
| 141 |
done) &
|
| 142 |
|
| 143 |
+
# ββ 8. Jalankan OpenClaw ββββββββββββββββββββββββββββββββββββββ
|
| 144 |
echo ">>> Running openclaw doctor --fix..."
|
| 145 |
openclaw doctor --fix
|
| 146 |
|
| 147 |
+
echo ">>> Starting OpenClaw on port $PORT..."
|
| 148 |
+
exec openclaw gateway run --port $PORT
|