deploy_agent_mcp.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. UNIT_SRC="../deploy/systemd/fwh-agent-mcp.service"
  10. UNIT_DST="/etc/systemd/system/fwh-agent-mcp.service"
  11. # ===== 编译程序 =====
  12. echo "🚀 Building $MCP_NAME..."
  13. GOOS=linux GOARCH=amd64 go build -o $MCP_NAME ./cmd/agent-mcp/
  14. # ===== 复制程序到目标路径 =====
  15. echo "📦 Copying binary to $MCP_PATH..."
  16. sudo mv $MCP_NAME $MCP_PATH
  17. sudo chmod +x $MCP_PATH
  18. # ===== 安装 / 更新 systemd 单元 =====
  19. if [ -f "$UNIT_SRC" ]; then
  20. if ! sudo cmp -s "$UNIT_SRC" "$UNIT_DST"; then
  21. echo "📝 Installing systemd unit $UNIT_DST..."
  22. sudo cp "$UNIT_SRC" "$UNIT_DST"
  23. sudo systemctl daemon-reload
  24. sudo systemctl enable fwh-agent-mcp
  25. fi
  26. fi
  27. # ===== 检查令牌 =====
  28. if ! grep -q '^AGENT_MCP_TOKEN=.\+' "$APP_DIR/.env" 2>/dev/null; then
  29. echo "⚠️ $APP_DIR/.env 中没有配置 AGENT_MCP_TOKEN,服务将拒绝启动"
  30. fi
  31. # ===== 重启 =====
  32. echo "🔁 Restarting fwh-agent-mcp..."
  33. sudo systemctl restart fwh-agent-mcp
  34. sleep 2
  35. sudo systemctl --no-pager --lines=5 status fwh-agent-mcp || true
  36. echo "✅ $MCP_NAME deployed to $MCP_PATH"