deploy_agent_mcp.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. set -e
  3. # 部署新 AI 助手的业务数据 MCP 服务 fwh-agent-mcp(与旧 MCP 的 deploy_mcp.sh 相互独立)
  4. # 用法:在 service/ 目录下执行 ./cmd/deploy_agent_mcp.sh
  5. # ===== 配置部分 =====
  6. MCP_NAME="fwh-agent-mcp"
  7. APP_DIR="/var/www/fwh-toolbox/server"
  8. MCP_PATH="$APP_DIR/$MCP_NAME"
  9. # 独立配置文件,示例见 deploy/config.agent-mcp.env.example
  10. CONFIG_PATH="$APP_DIR/config.agent-mcp.env"
  11. UNIT_SRC="../deploy/systemd/fwh-agent-mcp.service"
  12. UNIT_DST="/etc/systemd/system/fwh-agent-mcp.service"
  13. # ===== 编译程序 =====
  14. echo "🚀 Building $MCP_NAME..."
  15. GOOS=linux GOARCH=amd64 go build -o $MCP_NAME ./cmd/agent-mcp/
  16. # ===== 复制程序到目标路径 =====
  17. echo "📦 Copying binary to $MCP_PATH..."
  18. sudo mv $MCP_NAME $MCP_PATH
  19. sudo chmod +x $MCP_PATH
  20. # ===== 生成并拷贝 EMS 参数字典(ems_param_lookup 使用,启动时加载到 Redis) =====
  21. bash "$(dirname "$0")/deploy_emspara.sh"
  22. # ===== 安装 / 更新 systemd 单元 =====
  23. if [ -f "$UNIT_SRC" ]; then
  24. if ! sudo cmp -s "$UNIT_SRC" "$UNIT_DST"; then
  25. echo "📝 Installing systemd unit $UNIT_DST..."
  26. sudo cp "$UNIT_SRC" "$UNIT_DST"
  27. sudo systemctl daemon-reload
  28. sudo systemctl enable fwh-agent-mcp
  29. fi
  30. fi
  31. # ===== 检查配置 =====
  32. if [ ! -f "$CONFIG_PATH" ]; then
  33. echo "⚠️ 缺少 $CONFIG_PATH,服务将拒绝启动(cp deploy/config.agent-mcp.env.example 后修改)"
  34. elif ! grep -qE '^AGENT_MCP_TOKEN="?[^"[:space:]]' "$CONFIG_PATH" || grep -qE '^AGENT_MCP_TOKEN="?CHANGE_ME' "$CONFIG_PATH"; then
  35. echo "⚠️ $CONFIG_PATH 中没有配置 AGENT_MCP_TOKEN,服务将拒绝启动"
  36. fi
  37. # ===== 重启 =====
  38. echo "🔁 Restarting fwh-agent-mcp..."
  39. sudo systemctl restart fwh-agent-mcp
  40. sleep 2
  41. sudo systemctl --no-pager --lines=5 status fwh-agent-mcp || true
  42. echo "✅ $MCP_NAME deployed to $MCP_PATH"