| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #!/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"
- 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 ! grep -q '^AGENT_MCP_TOKEN=.\+' "$APP_DIR/.env" 2>/dev/null; then
- echo "⚠️ $APP_DIR/.env 中没有配置 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"
|