Upload 3 files
Browse files- start-openclaw.sh +39 -13
- sync.py +4 -3
start-openclaw.sh
CHANGED
|
@@ -5,13 +5,19 @@ echo "=========================================="
|
|
| 5 |
echo "OpenClaw Gateway 启动中..."
|
| 6 |
echo "=========================================="
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
echo "--- [INIT] 检查 HuggingFace 数据恢复 ---"
|
| 12 |
python3 /usr/local/bin/sync.py restore
|
| 13 |
|
| 14 |
-
if [ ! -f /
|
| 15 |
echo "--- [INIT] 无历史数据,需要初始备份 ---"
|
| 16 |
NEED_INITIAL_UPLOAD=true
|
| 17 |
fi
|
|
@@ -141,22 +147,37 @@ fi
|
|
| 141 |
|
| 142 |
AGENTS_CONFIG="$AGENTS_CONFIG }"
|
| 143 |
|
| 144 |
-
cat > /
|
| 145 |
{
|
| 146 |
"models": {
|
| 147 |
"providers": {
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
},
|
| 151 |
"agents": {
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
},
|
| 154 |
"gateway": {
|
| 155 |
"mode": "local",
|
| 156 |
"bind": "lan",
|
| 157 |
"port": 7860,
|
| 158 |
"trustedProxies": ["*"],
|
| 159 |
-
"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
|
| 160 |
"controlUi": {
|
| 161 |
"allowInsecureAuth": true,
|
| 162 |
"dangerouslyDisableDeviceAuth": true,
|
|
@@ -166,24 +187,29 @@ cat > /root/.openclaw/openclaw.json <<EOF
|
|
| 166 |
"channels": {
|
| 167 |
"feishu": {
|
| 168 |
"enabled": ${FEISHU_ENABLED:-false},
|
| 169 |
-
"appId": "$FEISHU_APP_ID",
|
| 170 |
-
"appSecret": "$FEISHU_APP_SECRET",
|
| 171 |
-
"dmPolicy": "open"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
}
|
| 174 |
}
|
| 175 |
EOF
|
| 176 |
|
| 177 |
echo "--- [INIT] 配置完成 ---"
|
| 178 |
-
cat /
|
| 179 |
|
| 180 |
if [ "$NEED_INITIAL_UPLOAD" = "true" ]; then
|
| 181 |
echo "--- [INIT] 执行初始备份到 HuggingFace ---"
|
| 182 |
-
python3 /usr/local/bin/sync.py backup
|
| 183 |
fi
|
| 184 |
|
| 185 |
echo "--- [INIT] 启动定时备份 ---"
|
| 186 |
-
(while true; do sleep 1200; python3 /usr/local/bin/sync.py backup; done) &
|
| 187 |
|
| 188 |
echo "--- [INIT] 启动 OpenClaw Gateway ---"
|
| 189 |
|
|
|
|
| 5 |
echo "OpenClaw Gateway 启动中..."
|
| 6 |
echo "=========================================="
|
| 7 |
|
| 8 |
+
# 确定正确的配置目录
|
| 9 |
+
OPENCLAW_DIR="/home/node/.openclaw"
|
| 10 |
+
if [ -d "/root/.openclaw" ]; then
|
| 11 |
+
OPENCLAW_DIR="/root/.openclaw"
|
| 12 |
+
fi
|
| 13 |
+
|
| 14 |
+
mkdir -p "$OPENCLAW_DIR/sessions"
|
| 15 |
+
mkdir -p "$OPENCLAW_DIR/workspace"
|
| 16 |
|
| 17 |
echo "--- [INIT] 检查 HuggingFace 数据恢复 ---"
|
| 18 |
python3 /usr/local/bin/sync.py restore
|
| 19 |
|
| 20 |
+
if [ ! -f "$OPENCLAW_DIR/openclaw.json" ]; then
|
| 21 |
echo "--- [INIT] 无历史数据,需要初始备份 ---"
|
| 22 |
NEED_INITIAL_UPLOAD=true
|
| 23 |
fi
|
|
|
|
| 147 |
|
| 148 |
AGENTS_CONFIG="$AGENTS_CONFIG }"
|
| 149 |
|
| 150 |
+
cat > "$OPENCLAW_DIR/openclaw.json" <<EOF
|
| 151 |
{
|
| 152 |
"models": {
|
| 153 |
"providers": {
|
| 154 |
+
"default": {
|
| 155 |
+
"baseUrl": "${PRIMARY_API_BASE:-https://api.openai.com/v1}",
|
| 156 |
+
"apiKey": "${PRIMARY_API_KEY:-}",
|
| 157 |
+
"api": "openai-completions",
|
| 158 |
+
"models": [
|
| 159 |
+
{
|
| 160 |
+
"id": "${PRIMARY_MODEL:-gpt-4o}",
|
| 161 |
+
"name": "主模型",
|
| 162 |
+
"contextWindow": 128000
|
| 163 |
+
}
|
| 164 |
+
]
|
| 165 |
+
}
|
| 166 |
}
|
| 167 |
},
|
| 168 |
"agents": {
|
| 169 |
+
"defaults": {
|
| 170 |
+
"model": {
|
| 171 |
+
"primary": "default/${PRIMARY_MODEL:-gpt-4o}"
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
},
|
| 175 |
"gateway": {
|
| 176 |
"mode": "local",
|
| 177 |
"bind": "lan",
|
| 178 |
"port": 7860,
|
| 179 |
"trustedProxies": ["*"],
|
| 180 |
+
"auth": { "mode": "token", "token": "${OPENCLAW_GATEWAY_PASSWORD:-admin123}" },
|
| 181 |
"controlUi": {
|
| 182 |
"allowInsecureAuth": true,
|
| 183 |
"dangerouslyDisableDeviceAuth": true,
|
|
|
|
| 187 |
"channels": {
|
| 188 |
"feishu": {
|
| 189 |
"enabled": ${FEISHU_ENABLED:-false},
|
| 190 |
+
"appId": "${FEISHU_APP_ID:-}",
|
| 191 |
+
"appSecret": "${FEISHU_APP_SECRET:-}",
|
| 192 |
+
"dmPolicy": "open",
|
| 193 |
+
"accounts": {
|
| 194 |
+
"default": {
|
| 195 |
+
"allowFrom": ["*"]
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
}
|
| 199 |
}
|
| 200 |
}
|
| 201 |
EOF
|
| 202 |
|
| 203 |
echo "--- [INIT] 配置完成 ---"
|
| 204 |
+
cat "$OPENCLAW_DIR/openclaw.json" | head -30
|
| 205 |
|
| 206 |
if [ "$NEED_INITIAL_UPLOAD" = "true" ]; then
|
| 207 |
echo "--- [INIT] 执行初始备份到 HuggingFace ---"
|
| 208 |
+
OPENCLAW_DIR="$OPENCLAW_DIR" python3 /usr/local/bin/sync.py backup
|
| 209 |
fi
|
| 210 |
|
| 211 |
echo "--- [INIT] 启动定时备份 ---"
|
| 212 |
+
(while true; do sleep 1200; OPENCLAW_DIR="$OPENCLAW_DIR" python3 /usr/local/bin/sync.py backup; done) &
|
| 213 |
|
| 214 |
echo "--- [INIT] 启动 OpenClaw Gateway ---"
|
| 215 |
|
sync.py
CHANGED
|
@@ -15,6 +15,7 @@ class DataSync:
|
|
| 15 |
self.api = HfApi()
|
| 16 |
self.repo_id = os.getenv("HF_DATASET")
|
| 17 |
self.token = os.getenv("HF_TOKEN")
|
|
|
|
| 18 |
|
| 19 |
def restore(self):
|
| 20 |
"""从 HuggingFace Dataset 恢复数据"""
|
|
@@ -43,8 +44,8 @@ class DataSync:
|
|
| 43 |
token=self.token
|
| 44 |
)
|
| 45 |
with tarfile.open(path, "r:gz") as tar:
|
| 46 |
-
tar.extractall(path=
|
| 47 |
-
print(f"--- [SYNC] 恢复成功! 数据已覆盖至
|
| 48 |
return True
|
| 49 |
|
| 50 |
print("--- [SYNC] 未找到最近 5 天的备份包 ---")
|
|
@@ -64,7 +65,7 @@ class DataSync:
|
|
| 64 |
with tarfile.open(name, "w:gz") as tar:
|
| 65 |
targets = ["sessions", "workspace", "agents", "memory", "openclaw.json"]
|
| 66 |
for target in targets:
|
| 67 |
-
full_path = f"
|
| 68 |
if os.path.exists(full_path):
|
| 69 |
tar.add(full_path, arcname=target)
|
| 70 |
|
|
|
|
| 15 |
self.api = HfApi()
|
| 16 |
self.repo_id = os.getenv("HF_DATASET")
|
| 17 |
self.token = os.getenv("HF_TOKEN")
|
| 18 |
+
self.openclaw_dir = os.getenv("OPENCLAW_DIR", "/root/.openclaw")
|
| 19 |
|
| 20 |
def restore(self):
|
| 21 |
"""从 HuggingFace Dataset 恢复数据"""
|
|
|
|
| 44 |
token=self.token
|
| 45 |
)
|
| 46 |
with tarfile.open(path, "r:gz") as tar:
|
| 47 |
+
tar.extractall(path=self.openclaw_dir)
|
| 48 |
+
print(f"--- [SYNC] 恢复成功! 数据已覆盖至 {self.openclaw_dir} ---")
|
| 49 |
return True
|
| 50 |
|
| 51 |
print("--- [SYNC] 未找到最近 5 天的备份包 ---")
|
|
|
|
| 65 |
with tarfile.open(name, "w:gz") as tar:
|
| 66 |
targets = ["sessions", "workspace", "agents", "memory", "openclaw.json"]
|
| 67 |
for target in targets:
|
| 68 |
+
full_path = f"{self.openclaw_dir}/{target}"
|
| 69 |
if os.path.exists(full_path):
|
| 70 |
tar.add(full_path, arcname=target)
|
| 71 |
|