guanghulab/scripts/engine-start.sh
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

139 lines
6.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ══════════════════════════════════════════════════════════════
# 光湖驱动引擎 · 铸渊服务器安装脚本
# Guanghu Drive Engine · Zhuyuan Server Installer
#
# 用途:一步完成:大脑同步 + 引擎安装 + 自动启动
# 用法bash scripts/engine-start.sh
#
# 依赖Node.js (服务器应有)零npm依赖
# 版权:国作登字-2026-A-00037559 · TCS-0002∞
# ══════════════════════════════════════════════════════════════
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m'
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
ENGINE_PORT="${GATEKEEPER_PORT:-3910}"
clear
echo ""
echo "╔══════════════════════════════════════════════╗"
echo "║ 光湖驱动引擎 · 安装脚本 ║"
echo "║ Guanghu Drive Engine · Installer v1.0 ║"
echo "╚══════════════════════════════════════════════╝"
echo ""
echo -e " ${CYAN}仓库目录:${NC} ${REPO_DIR}"
echo -e " ${CYAN}引擎端口:${NC} ${ENGINE_PORT}"
echo ""
# ══════════════════════════════════════════════════════════════
# 第1步检查依赖
# ══════════════════════════════════════════════════════════════
echo -e "${YELLOW}[1/4] 检查环境...${NC}"
if ! command -v node &> /dev/null; then
echo -e " ${RED}❌ 需要 Node.js 但未安装${NC}"
echo " 请先安装: apt install nodejs npm"
exit 1
fi
NODE_VER=$(node -v)
echo -e " ${GREEN}✅ Node.js ${NODE_VER}${NC}"
# ══════════════════════════════════════════════════════════════
# 第2步运行大脑同步
# ══════════════════════════════════════════════════════════════
echo ""
echo -e "${YELLOW}[2/4] 同步大脑文件...${NC}"
if [ -f "${REPO_DIR}/scripts/brain-sync.js" ]; then
node "${REPO_DIR}/scripts/brain-sync.js"
echo -e " ${GREEN}✅ 大脑同步完成${NC}"
else
echo -e " ${YELLOW}⚠️ 未找到 brain-sync.js跳过${NC}"
fi
# ══════════════════════════════════════════════════════════════
# 第3步启动引擎
# ══════════════════════════════════════════════════════════════
echo ""
echo -e "${YELLOW}[3/4] 启动引擎...${NC}"
GATEKEEPER="${REPO_DIR}/mcp-servers/zhuyuan-gateway/gatekeeper/index.js"
if [ ! -f "$GATEKEEPER" ]; then
echo -e " ${RED}❌ 未找到引擎文件: ${GATEKEEPER}${NC}"
exit 1
fi
# 检查是否已有引擎在运行
if lsof -i :${ENGINE_PORT} &>/dev/null 2>&1; then
echo -e " ${YELLOW}⚠️ 引擎已在端口 ${ENGINE_PORT} 运行${NC}"
echo -e " ${YELLOW} 如需重启: fuser -k ${ENGINE_PORT}/tcp && node ${GATEKEEPER} ${ENGINE_PORT} &${NC}"
else
# 后台启动
nohup node "${GATEKEEPER}" "${ENGINE_PORT}" > /tmp/zhuyuan-engine.log 2>&1 &
ENGINE_PID=$!
sleep 2
if kill -0 $ENGINE_PID 2>/dev/null; then
echo -e " ${GREEN}✅ 引擎已启动 (PID: ${ENGINE_PID})${NC}"
else
echo -e " ${RED}❌ 引擎启动失败,查看日志: cat /tmp/zhuyuan-engine.log${NC}"
exit 1
fi
fi
# ══════════════════════════════════════════════════════════════
# 第4步显示信息
# ══════════════════════════════════════════════════════════════
echo ""
echo -e "${YELLOW}[4/4] 服务状态...${NC}"
# 检查端口
if lsof -i :${ENGINE_PORT} &>/dev/null 2>&1; then
echo -e " ${GREEN}✅ 引擎端口 ${ENGINE_PORT} 开放中${NC}"
else
echo -e " ${RED}❌ 引擎端口 ${ENGINE_PORT} 未开放${NC}"
fi
# 获取API密钥
HOME=${HOME:-/root}
SECRET_FILE="${HOME}/.gatekeeper/secret"
if [ -f "$SECRET_FILE" ]; then
API_KEY=$(cat "$SECRET_FILE")
else
API_KEY="等待首次启动生成"
fi
echo ""
echo "══════════════════════════════════════════════"
echo " 光湖驱动引擎 · 安装完成"
echo ""
echo " ╭─ API 密钥"
echo " ├─ ${API_KEY}"
echo " ╰─ (保存在 ~/.gatekeeper/secret)"
echo ""
echo " 向铸渊发送以下信息:"
echo " ┌──────────────────────────────────────────┐"
echo " │ 服务器: 广州 (43.139.217.141) │"
echo " │ 端口: ${ENGINE_PORT}"
echo " │ 密钥: ${API_KEY}"
echo " └──────────────────────────────────────────┘"
echo ""
echo " 日志: tail -f /tmp/zhuyuan-engine.log"
echo "══════════════════════════════════════════════"
echo ""
# 自动开机启动提示
if ! command -v pm2 &> /dev/null; then
echo -e " ${YELLOW}提示: 当前未使用进程管理工具,服务器重启后需重新启动引擎${NC}"
echo " 建议: npm install -g pm2 && pm2 start ${GATEKEEPER} -- -p ${ENGINE_PORT}"
echo ""
fi