File size: 1,646 Bytes
101dd80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# AgentFrame 一键部署脚本 (本机 systemd)
set -e

FRAMEWORK_DIR="/root/.openclaw/workspace/agentframe"
INSTALL_DIR="/opt/agentframe"
STATE_DIR="/var/lib/agentframe"

echo "📦 AgentFrame 部署脚本"
echo "======================"

# 1. 复制到 /opt
if [ ! -d "$INSTALL_DIR" ]; then
    mkdir -p "$INSTALL_DIR"; cp -r "$FRAMEWORK_DIR" "$INSTALL_DIR/agentframe"
    echo "✅ 已复制到 $INSTALL_DIR"
else
    cp -r "$FRAMEWORK_DIR" "$INSTALL_DIR/"
    echo "✅ 已更新 $INSTALL_DIR"
fi

# 2. 状态目录
mkdir -p "$STATE_DIR"
echo "✅ 状态目录: $STATE_DIR"

# 3. systemd 服务
cp "$FRAMEWORK_DIR/deploy/agentframe.service" /etc/systemd/system/agentframe.service
# 修正工作目录
sed -i "s|WorkingDirectory=/opt/agentframe|WorkingDirectory=$INSTALL_DIR/agentframe|" /etc/systemd/system/agentframe.service
systemctl daemon-reload
systemctl enable agentframe
echo "✅ systemd 服务已注册"

# 4. API key 检查
if [ -z "$AGENTFRAME_API_KEY" ]; then
    echo "⚠️ 未设置 AGENTFRAME_API_KEY, 服务将使用 mock (离线模式)"
    echo "   设置: export AGENTFRAME_API_KEY=sk-xxx 后重启服务"
else
    sed -i "s|Environment=\"AGENTFRAME_API_KEY=.*|Environment=\"AGENTFRAME_API_KEY=$AGENTFRAME_API_KEY\"|" /etc/systemd/system/agentframe.service
    systemctl daemon-reload
    echo "✅ API key 已配置"
fi

# 5. 启动
systemctl restart agentframe || true
sleep 2
if systemctl is-active agentframe >/dev/null 2>&1; then
    echo "✅ 服务运行中: http://0.0.0.0:8090/health"
else
    echo "⚠️ 服务启动失败, 查看日志: journalctl -u agentframe -n 50"
fi

echo "完成!"