sharween commited on
Commit
c0c874d
·
verified ·
1 Parent(s): 3e32c02

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +21 -10
start-openclaw.sh CHANGED
@@ -9,25 +9,27 @@ HF_TOKEN="${HF_TOKEN}"
9
  BACKUP_FILE="latest_backup.tar.gz"
10
 
11
  # -------------------------------------------------
12
- # 1️⃣ 若存在备份,先恢复整个 .openclaw(包括微信 accounts)
13
  # -------------------------------------------------
14
  if [[ -n "$REPO_ID" && -n "$HF_TOKEN" ]]; then
15
  echo "🔁 正在从 HuggingFace 下载并恢复备份 …"
16
- python3 /app/sync.py restore # 运行您提供的脚本(restore)
17
  else
18
- echo "⚠️ HF_DATASET/HF_TOKEN 未设,跳过远端恢复"
19
  fi
20
 
21
  # -------------------------------------------------
22
- # 2️⃣ 确保微信 accounts 目录存在(恢复后会自动出现)
23
  # -------------------------------------------------
24
  mkdir -p /root/.openclaw/openclaw-weixin/accounts
25
 
26
  # -------------------------------------------------
27
- # 3️⃣ 只在第一次启动时安装微信插件(后续不再执行)
 
28
  # -------------------------------------------------
29
- if [[ ! -d /root/.openclaw/openclaw-weixin/accounts || -z "$(ls -A /root/.openclaw/openclaw-weixin/accounts)" ]]; then
30
  echo "📦 首次安装微信插件 …"
 
31
  npx -y @tencent-weixin/openclaw-weixin-cli@latest install --no-restart || true
32
  else
33
  echo "✅ 微信插件已存在,跳过 reinstall"
@@ -85,20 +87,29 @@ cat > /root/.openclaw/openclaw.json <<EOF
85
  EOF
86
 
87
  # -------------------------------------------------
88
- # 7️⃣ (建议)去掉 doctor --fix,防止 token 被删除
 
 
 
 
 
 
 
 
 
89
  # -------------------------------------------------
90
  # openclaw doctor --fix # 如需自检请手动执行
91
 
92
  # -------------------------------------------------
93
- # 8️⃣ 启动定时备份(每 1 小时)并同步到 HuggingFace
94
  # -------------------------------------------------
95
  ( while true; do
96
  sleep 3600
97
  echo "🗄️ 执行周期备份 …"
98
- python3 /app/restore_weixin.py backup # 运行您提供的同一脚本(backup)
99
  done ) &
100
 
101
  # -------------------------------------------------
102
- # 9️⃣ 启动网关(前台运行,确保在恢复后启动)
103
  # -------------------------------------------------
104
  exec openclaw gateway run --port $PORT
 
9
  BACKUP_FILE="latest_backup.tar.gz"
10
 
11
  # -------------------------------------------------
12
+ # 1️⃣ 若提供 HF_DATASET/HF_TOKEN先恢复远端备份(包括微信 accounts)
13
  # -------------------------------------------------
14
  if [[ -n "$REPO_ID" && -n "$HF_TOKEN" ]]; then
15
  echo "🔁 正在从 HuggingFace 下载并恢复备份 …"
16
+ python3 /app/sync.py restore # 恢复 .openclaw 全目录
17
  else
18
+ echo "⚠️ HF_DATASET / HF_TOKEN 未设,跳过远端恢复"
19
  fi
20
 
21
  # -------------------------------------------------
22
+ # 2️⃣ 确保微信 accounts 目录存在(恢复后会自动出现,若没有则新建
23
  # -------------------------------------------------
24
  mkdir -p /root/.openclaw/openclaw-weixin/accounts
25
 
26
  # -------------------------------------------------
27
+ # 3️⃣ 只在第一次启动时安装微信插件(后续启动不再执行)
28
+ # 检查条件:若插件主目录不存在 或 目录为空 → 重新安装
29
  # -------------------------------------------------
30
+ if [[ ! -d /root/.openclaw/openclaw-weixin || -z "$(ls -A /root/.openclaw/openclaw-weixin)" ]]; then
31
  echo "📦 首次安装微信插件 …"
32
+ # 加上 --no-restart 防止安装过程触发网关自动重启
33
  npx -y @tencent-weixin/openclaw-weixin-cli@latest install --no-restart || true
34
  else
35
  echo "✅ 微信插件已存在,跳过 reinstall"
 
87
  EOF
88
 
89
  # -------------------------------------------------
90
+ # 7️⃣ 微信 token 持久化处理(复制持久化的 accounts 目录)
91
+ # -------------------------------------------------
92
+ mkdir -p /workspace/openclaw_data/weixin_accounts
93
+ if [[ -d /workspace/openclaw_data/weixin_accounts && -n "$(ls -A /workspace/openclaw_data/weixin_accounts)" ]]; then
94
+ echo "🔄 正在恢复持久化的微信 accounts …"
95
+ cp -r /workspace/openclaw_data/weixin_accounts/* /root/.openclaw/openclaw-weixin/accounts/
96
+ fi
97
+
98
+ # -------------------------------------------------
99
+ # 8️⃣ (可选)去掉 doctor --fix,防止 token 被删除
100
  # -------------------------------------------------
101
  # openclaw doctor --fix # 如需自检请手动执行
102
 
103
  # -------------------------------------------------
104
+ # 9️⃣ 启动定时备份(每 1 小时)并同步到 HuggingFace(可自行改为自定义脚本)
105
  # -------------------------------------------------
106
  ( while true; do
107
  sleep 3600
108
  echo "🗄️ 执行周期备份 …"
109
+ python3 /app/sync.py backup
110
  done ) &
111
 
112
  # -------------------------------------------------
113
+ # 1️⃣0️⃣ 启动网关(前台运行,确保在恢复后启动)
114
  # -------------------------------------------------
115
  exec openclaw gateway run --port $PORT