forked from xianyu110/awesome-openclaw-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-launchd.sh
More file actions
executable file
·144 lines (118 loc) · 3.6 KB
/
Copy pathsetup-launchd.sh
File metadata and controls
executable file
·144 lines (118 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/zsh
# OpenClaw 多 Gateway 保活配置脚本
# 使用 macOS launchd 实现开机自启动和自动重启
echo "🚀 配置 OpenClaw 多 Gateway 保活"
echo "===================================="
echo ""
# 检查 openclaw 路径
OPENCLAW_PATH=$(which openclaw)
if [ -z "$OPENCLAW_PATH" ]; then
echo "❌ 未找到 openclaw 命令"
echo "请先安装 OpenClaw"
exit 1
fi
echo "✅ OpenClaw 路径: $OPENCLAW_PATH"
echo ""
# 定义 4 个 profiles
profiles=("main-assistant" "content-creator" "tech-dev" "ai-news")
ports=(18789 18790 18791 18792)
# 创建 LaunchAgents 目录
mkdir -p ~/Library/LaunchAgents
echo "📝 创建 launchd 配置文件..."
echo ""
for i in {1..4}; do
profile="${profiles[$i]}"
port="${ports[$i]}"
plist_file="$HOME/Library/LaunchAgents/com.openclaw.$profile.plist"
echo "创建 $profile 配置..."
cat > "$plist_file" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.openclaw.$profile</string>
<key>ProgramArguments</key>
<array>
<string>$OPENCLAW_PATH</string>
<string>--profile</string>
<string>$profile</string>
<string>gateway</string>
<string>run</string>
<string>--port</string>
<string>$port</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>StandardOutPath</key>
<string>$HOME/.openclaw-$profile/stdout.log</string>
<key>StandardErrorPath</key>
<string>$HOME/.openclaw-$profile/stderr.log</string>
<key>WorkingDirectory</key>
<string>$HOME</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>ThrottleInterval</key>
<integer>10</integer>
</dict>
</plist>
EOF
echo " ✅ 已创建 $plist_file"
done
echo ""
echo "🔧 加载 launchd 服务..."
echo ""
for profile in "${profiles[@]}"; do
plist_file="$HOME/Library/LaunchAgents/com.openclaw.$profile.plist"
# 先卸载(如果已存在)
launchctl unload "$plist_file" 2>/dev/null
# 加载服务
launchctl load "$plist_file"
if [ $? -eq 0 ]; then
echo " ✅ $profile 服务已加载"
else
echo " ❌ $profile 服务加载失败"
fi
done
echo ""
echo "===================================="
echo "✅ 配置完成!"
echo ""
echo "📋 服务说明:"
echo ""
echo "1. 开机自启动:所有 Gateway 会在开机时自动启动"
echo "2. 自动重启:如果进程崩溃,会在 10 秒后自动重启"
echo "3. 日志位置:"
echo " - stdout: ~/.openclaw-<profile>/stdout.log"
echo " - stderr: ~/.openclaw-<profile>/stderr.log"
echo ""
echo "📝 管理命令:"
echo ""
echo "# 查看服务状态"
echo "launchctl list | grep openclaw"
echo ""
echo "# 停止某个服务"
echo "launchctl unload ~/Library/LaunchAgents/com.openclaw.main-assistant.plist"
echo ""
echo "# 启动某个服务"
echo "launchctl load ~/Library/LaunchAgents/com.openclaw.main-assistant.plist"
echo ""
echo "# 重启某个服务"
echo "launchctl unload ~/Library/LaunchAgents/com.openclaw.main-assistant.plist"
echo "launchctl load ~/Library/LaunchAgents/com.openclaw.main-assistant.plist"
echo ""
echo "# 停止所有服务"
echo "./stop-launchd.sh"
echo ""
echo "# 查看日志"
echo "tail -f ~/.openclaw-main-assistant/stdout.log"
echo ""