| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/bin/bash
- set -e
- # 部署新 AI 助手的业务数据 MCP 服务 fwh-agent-mcp(与旧 MCP 的 deploy_mcp.sh 相互独立)
- # 用法:在 service/ 目录下执行 ./cmd/deploy_agent_mcp.sh
- # ===== 配置部分 =====
- MCP_NAME="fwh-agent-mcp"
- APP_DIR="/var/www/fwh-toolbox/server"
- MCP_PATH="$APP_DIR/$MCP_NAME"
- # 独立配置文件,示例见 deploy/config.agent-mcp.env.example
- CONFIG_PATH="$APP_DIR/config.agent-mcp.env"
- UNIT_SRC="../deploy/systemd/fwh-agent-mcp.service"
- UNIT_DST="/etc/systemd/system/fwh-agent-mcp.service"
- # ===== 编译程序 =====
- echo "🚀 Building $MCP_NAME..."
- GOOS=linux GOARCH=amd64 go build -o $MCP_NAME ./cmd/agent-mcp/
- # ===== 复制程序到目标路径 =====
- echo "📦 Copying binary to $MCP_PATH..."
- sudo mv $MCP_NAME $MCP_PATH
- sudo chmod +x $MCP_PATH
- # ===== 安装 / 更新 systemd 单元 =====
- if [ -f "$UNIT_SRC" ]; then
- if ! sudo cmp -s "$UNIT_SRC" "$UNIT_DST"; then
- echo "📝 Installing systemd unit $UNIT_DST..."
- sudo cp "$UNIT_SRC" "$UNIT_DST"
- sudo systemctl daemon-reload
- sudo systemctl enable fwh-agent-mcp
- fi
- fi
- # ===== 检查配置 =====
- if [ ! -f "$CONFIG_PATH" ]; then
- echo "⚠️ 缺少 $CONFIG_PATH,服务将拒绝启动(cp deploy/config.agent-mcp.env.example 后修改)"
- elif ! grep -qE '^AGENT_MCP_TOKEN="?[^"[:space:]]' "$CONFIG_PATH" || grep -qE '^AGENT_MCP_TOKEN="?CHANGE_ME' "$CONFIG_PATH"; then
- echo "⚠️ $CONFIG_PATH 中没有配置 AGENT_MCP_TOKEN,服务将拒绝启动"
- fi
- # ===== 重启 =====
- echo "🔁 Restarting fwh-agent-mcp..."
- sudo systemctl restart fwh-agent-mcp
- sleep 2
- sudo systemctl --no-pager --lines=5 status fwh-agent-mcp || true
- echo "✅ $MCP_NAME deployed to $MCP_PATH"
|