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

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +36 -39
start-openclaw.sh CHANGED
@@ -1,59 +1,57 @@
1
  #!/usr/bin/env bash
2
  set -e
3
 
4
- # -------------------------------------------------
5
- # 0️⃣ 环境变量(HuggingFace 数据集 ID 与 token必须已设
6
- # -------------------------------------------------
7
  REPO_ID="${HF_DATASET}"
8
  HF_TOKEN="${HF_TOKEN}"
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"
36
  fi
37
 
38
- # -------------------------------------------------
39
- # 4️⃣ 目录准备(保持原有结构)
40
- # -------------------------------------------------
41
  mkdir -p /root/.openclaw/agents/main/sessions
42
  mkdir -p /root/.openclaw/credentials
43
  mkdir -p /root/.openclaw/sessions
44
  mkdir -p /root/.openclaw/config/plugins.entries
45
 
46
- # -------------------------------------------------
47
- # 5️⃣ 处理 OpenAI API 地址(保持原有逻辑)
48
- # -------------------------------------------------
49
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
50
  | sed "s|/chat/completions||g" \
51
  | sed "s|/v1/|/v1|g" \
52
  | sed "s|/v1$|/v1|g")
53
 
54
- # -------------------------------------------------
55
- # 6️⃣ 生成 OpenClaw 主配置文件
56
- # -------------------------------------------------
57
  cat > /root/.openclaw/openclaw.json <<EOF
58
  {
59
  "models": {
@@ -86,30 +84,29 @@ cat > /root/.openclaw/openclaw.json <<EOF
86
  }
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
 
1
  #!/usr/bin/env bash
2
  set -e
3
 
4
+ # -----------------------------
5
+ # 0️⃣ 环境变量(HF_DATASET/HF_TOKEN
6
+ # -----------------------------
7
  REPO_ID="${HF_DATASET}"
8
  HF_TOKEN="${HF_TOKEN}"
9
  BACKUP_FILE="latest_backup.tar.gz"
10
 
11
+ # -----------------------------
12
+ # 1️⃣ 远端恢复如果有
13
+ # -----------------------------
14
  if [[ -n "$REPO_ID" && -n "$HF_TOKEN" ]]; then
15
  echo "🔁 正在从 HuggingFace 下载并恢复备份 …"
16
+ python3 /app/sync.py restore # 恢复 .openclaw 全目录,包括 accounts
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/src || -z "$(ls -A /root/.openclaw/openclaw-weixin/src)" ]]; then
30
+ echo "📦 首次或重新安装微信插件 "
 
 
31
  npx -y @tencent-weixin/openclaw-weixin-cli@latest install --no-restart || true
32
  else
33
  echo "✅ 微信插件已存在,跳过 reinstall"
34
  fi
35
 
36
+ # -----------------------------
37
+ # 4️⃣ 其他目录准备
38
+ # -----------------------------
39
  mkdir -p /root/.openclaw/agents/main/sessions
40
  mkdir -p /root/.openclaw/credentials
41
  mkdir -p /root/.openclaw/sessions
42
  mkdir -p /root/.openclaw/config/plugins.entries
43
 
44
+ # -----------------------------
45
+ # 5️⃣ 处理 OpenAI API 地址
46
+ # -----------------------------
47
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" \
48
  | sed "s|/chat/completions||g" \
49
  | sed "s|/v1/|/v1|g" \
50
  | sed "s|/v1$|/v1|g")
51
 
52
+ # -----------------------------
53
+ # 6️⃣ 生成 openclaw.json
54
+ # -----------------------------
55
  cat > /root/.openclaw/openclaw.json <<EOF
56
  {
57
  "models": {
 
84
  }
85
  EOF
86
 
87
+ # -----------------------------
88
+ # 7️⃣ 微信 token 持久化处理(复持久化 accounts)
89
+ # -----------------------------
 
90
  if [[ -d /workspace/openclaw_data/weixin_accounts && -n "$(ls -A /workspace/openclaw_data/weixin_accounts)" ]]; then
91
  echo "🔄 正在恢复持久化的微信 accounts …"
92
  cp -r /workspace/openclaw_data/weixin_accounts/* /root/.openclaw/openclaw-weixin/accounts/
93
  fi
94
 
95
+ # -----------------------------
96
+ # 8️⃣ (建议)去掉 doctor --fix
97
+ # -----------------------------
98
  # openclaw doctor --fix # 如需自检请手动执行
99
 
100
+ # -----------------------------
101
+ # 9️⃣ 定时备份(每小时)并同步到 HF
102
+ # -----------------------------
103
  ( while true; do
104
  sleep 3600
105
  echo "🗄️ 执行周期备份 …"
106
  python3 /app/sync.py backup
107
  done ) &
108
 
109
+ # -----------------------------
110
+ # 10️⃣ 启动网关
111
+ # -----------------------------
112
  exec openclaw gateway run --port $PORT