aip9105 commited on
Commit
a09f6f4
·
verified ·
1 Parent(s): a8a86d0

Update start-openclaw.sh

Browse files
Files changed (1) hide show
  1. start-openclaw.sh +57 -14
start-openclaw.sh CHANGED
@@ -1,18 +1,27 @@
1
  #!/bin/bash
2
  set -e
3
 
4
- # 1. 补全目录
5
  mkdir -p /root/.openclaw/agents/main/sessions
6
  mkdir -p /root/.openclaw/credentials
7
  mkdir -p /root/.openclaw/sessions
8
 
9
- # 2. 执行恢复
10
  python3 /app/sync.py restore
11
 
12
- # 3. 理 API 地址
 
13
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed "s|/chat/completions||g" | sed "s|/v1/|/v1|g" | sed "s|/v1$|/v1|g")
14
 
15
- # 4. 生成配文件
 
 
 
 
 
 
 
 
16
  cat > /root/.openclaw/openclaw.json <<EOF
17
  {
18
  "models": {
@@ -32,17 +41,17 @@ cat > /root/.openclaw/openclaw.json <<EOF
32
  "restart": true
33
  },
34
  "gateway": {
35
- "mode": "local", "bind": "lan", "port": $PORT,
36
- "trustedProxies": ["0.0.0.0/0"],
37
  "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
38
  "controlUi": {
39
- "allowedOrigins": [
40
  "https://aip9105-openclaw.hf.space/"
41
  ],
42
  "dangerouslyAllowHostHeaderOriginFallback": true,
43
  "allowInsecureAuth": true,
44
  "dangerouslyDisableDeviceAuth": true
45
- }
46
  },
47
  "skills": {
48
  "entries": {
@@ -52,14 +61,48 @@ cat > /root/.openclaw/openclaw.json <<EOF
52
  }
53
  }
54
  }
55
-
56
  }
57
  EOF
58
 
59
- # 5. 启动定时备份 (每 1 小时)
60
- (while true; do sleep 3600; python3 /app/sync.py backup; done) &
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
 
 
 
 
 
62
 
63
- # 6. 运行
64
- openclaw doctor --fix
65
- exec openclaw gateway run --port $PORT
 
1
  #!/bin/bash
2
  set -e
3
 
4
+ # 1. 创建必要的目录
5
  mkdir -p /root/.openclaw/agents/main/sessions
6
  mkdir -p /root/.openclaw/credentials
7
  mkdir -p /root/.openclaw/sessions
8
 
9
+ # 2. 从持久化存储恢复数据
10
  python3 /app/sync.py restore
11
 
12
+ # 3. 和格式化 API 地址
13
+ # 移除可能存在的 /chat/completions 和调整 /v1 路径
14
  CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed "s|/chat/completions||g" | sed "s|/v1/|/v1|g" | sed "s|/v1$|/v1|g")
15
 
16
+ # 4. 更安全的绑定地址
17
+ # 在容器环境中,通常绑定到 0.0.0.0 是安全的,但可以限制为 127.0.0.1
18
+ # 如果需要在容器外访问,则保持 0.0.0.0
19
+ BIND_ADDRESS="0.0.0.0"
20
+ if [ -n "$RESTRICT_TO_LOCALHOST" ] && [ "$RESTRICT_TO_LOCALHOST" = "true" ]; then
21
+ BIND_ADDRESS="127.0.0.1"
22
+ fi
23
+
24
+ # 5. 生成主配置文件
25
  cat > /root/.openclaw/openclaw.json <<EOF
26
  {
27
  "models": {
 
41
  "restart": true
42
  },
43
  "gateway": {
44
+ "mode": "local", "bind": "$BIND_ADDRESS", "port": $PORT,
45
+ "trustedProxies": ["127.0.0.1/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
46
  "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
47
  "controlUi": {
48
+ "allowedOrigins": [
49
  "https://aip9105-openclaw.hf.space/"
50
  ],
51
  "dangerouslyAllowHostHeaderOriginFallback": true,
52
  "allowInsecureAuth": true,
53
  "dangerouslyDisableDeviceAuth": true
54
+ }
55
  },
56
  "skills": {
57
  "entries": {
 
61
  }
62
  }
63
  }
 
64
  }
65
  EOF
66
 
67
+ # 6. 修复权限问题(根据 doctor 建议)
68
+ chmod 700 /root/.openclaw
69
+ chmod 600 /root/.openclaw/openclaw.json
70
+ chmod 700 /root/.openclaw/agents
71
+ chmod 700 /root/.openclaw/credentials
72
+ chmod 700 /root/.openclaw/sessions
73
+
74
+ # 7. 安装常见技能依赖
75
+ # 注意:这些包应该在 Dockerfile 中安装,这里作为后备方案
76
+ if ! command -v curl &> /dev/null; then
77
+ apt-get update && apt-get install -y --no-install-recommends curl
78
+ fi
79
+
80
+ if ! command -v wget &> /dev/null; then
81
+ apt-get update && apt-get install -y --no-install-recommends wget
82
+ fi
83
+
84
+ # 8. 启动定时备份任务(每小时一次)
85
+ (
86
+ while true; do
87
+ sleep 3600
88
+ python3 /app/sync.py backup
89
+ done
90
+ ) &
91
+
92
+ # 9. 运行健康检查和修复
93
+ echo "运行 OpenClaw 健康检查..."
94
+ if openclaw doctor --fix; then
95
+ echo "健康检查完成,修复了发现的问题。"
96
+ else
97
+ echo "健康检查发现问题,但将继续启动..."
98
+ fi
99
 
100
+ # 10. 安全审计(可选)
101
+ if [ -n "$RUN_SECURITY_AUDIT" ] && [ "$RUN_SECURITY_AUDIT" = "true" ]; then
102
+ echo "运行安全审计..."
103
+ openclaw security audit --deep || true
104
+ fi
105
 
106
+ # 11. 启动 OpenClaw 网关
107
+ echo "启动 OpenClaw 网关,端口: $PORT,绑定地址: $BIND_ADDRESS"
108
+ exec openclaw gateway run --port $PORT