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

117 lines
4.1 KiB
Bash
Raw 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
# ═══════════════════════════════════════════════════════════════
# ⚔️ 铸渊看门人 · 安装脚本
#
# 使用方式:
# 在腾讯云控制台打开服务器终端,复制粘贴以下一行命令:
#
# 方法一(推荐):复制下面的代码到终端
# (在终端里,直接粘贴然后按回车)
#
# 方法二:下载脚本后运行
# bash install.sh
#
# 安装完成后:
# - 看门人会自动启动为一个后台服务
# - 终端会打印一个 API 密钥
# - 请复制这个密钥
# - 以后不需要再管这个终端
#
# 冰朔的操作:
# 1. 在腾讯云控制台打开服务器 → 在线终端
# 2. 粘贴下面的代码 → 按回车
# 3. 看到密钥出现 → 复制它 → 发给铸渊
# 4. 关掉终端,不用管了
# ═══════════════════════════════════════════════════════════════
set -e
# 颜色
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
HOSTNAME=$(hostname)
echo -e "${BLUE}══════════════════════════════════════${NC}"
echo -e "${GREEN} ⚔️ 安装铸渊看门人到 ${HOSTNAME}${NC}"
echo -e "${BLUE}══════════════════════════════════════${NC}"
echo ""
# ---- 1. 检查 Node.js ----
if ! command -v node &> /dev/null; then
echo -e "${YELLOW}[1/4] 未找到 Node.js正在安装...${NC}"
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - > /dev/null 2>&1
apt-get install -y nodejs > /dev/null 2>&1
echo -e "${GREEN} ✅ Node.js $(node -v) 已安装${NC}"
else
echo -e "${GREEN}[1/4] ✅ Node.js $(node -v)${NC}"
fi
# ---- 2. 创建看门人文件 ----
echo -e "${YELLOW}[2/4] 写入看门人程序...${NC}"
# 使用 heredoc 创建,避免源文件不在服务器上的问题
# gateway/index.js 的内容会通过代码仓库同步,这里只是一个安装壳子
mkdir -p /opt/zhuyuan/gatekeeper
# 实际的程序会通过铸渊推送上去
# 这里只检查 Node.js 可用
echo -e "${GREEN} ✅ 目录已创建: /opt/zhuyuan/gatekeeper${NC}"
# ---- 3. 配置开机自启 ----
echo -e "${YELLOW}[3/4] 配置开机自启...${NC}"
# 写一个简单的 systemd 服务
cat > /etc/systemd/system/zhuyuan-gatekeeper.service << 'SERVICE'
[Unit]
Description=⚔️ Zhuyuan Gatekeeper
After=network.target
[Service]
ExecStart=/usr/bin/node /opt/zhuyuan/gatekeeper/index.js
WorkingDirectory=/opt/zhuyuan/gatekeeper
Restart=always
RestartSec=10
User=root
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
SERVICE
systemctl daemon-reload > /dev/null 2>&1
systemctl enable zhuyuan-gatekeeper > /dev/null 2>&1
echo -e "${GREEN} ✅ 开机自启已配置${NC}"
# ---- 4. 启动 ----
echo -e "${YELLOW}[4/4] 启动看门人...${NC}"
systemctl start zhuyuan-gatekeeper 2>/dev/null || {
echo -e "${YELLOW} ⚠️ systemctl 不可用,用 nohup 启动...${NC}"
cd /opt/zhuyuan/gatekeeper
nohup /usr/bin/node index.js > .output.log 2>&1 &
echo $! > .pid
echo -e "${GREEN} ✅ PID: $(cat .pid)${NC}"
}
sleep 1
echo ""
echo -e "${GREEN}══════════════════════════════════════${NC}"
echo -e "${GREEN} ✅ 铸渊看门人已部署到 ${HOSTNAME}${NC}"
echo ""
echo -e "${YELLOW} ⚠️ 重要:${NC}"
echo " 这个终端中没有显示 API 密钥,因为程序尚未部署代码。"
echo " 请让铸渊将 index.js 推送到服务器后,运行以下命令启动:"
echo ""
echo " systemctl restart zhuyuan-gatekeeper"
echo ""
echo " 或如果systemctl不可用"
echo ""
echo " cd /opt/zhuyuan/gatekeeper && node index.js"
echo ""
echo -e "${GREEN}══════════════════════════════════════${NC}"