From 59ce18c1c57a0b90e7db58da06ca377ff2514e96 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 08:40:54 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix(proxy):=20=E4=BF=AE=E5=A4=8D=E9=93=B8?= =?UTF-8?q?=E6=B8=8A=E4=B8=93=E7=BA=BF=E9=83=A8=E7=BD=B23=E4=B8=AA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E2=80=94=20ufw=E8=AD=A6=E5=91=8A=E6=8A=91?= =?UTF-8?q?=E5=88=B6=E3=80=81PM2=E6=9C=8D=E5=8A=A1=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=87=8D=E6=9E=84(startOrRestart)=E3=80=81=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7N/A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. deploy-proxy.sh: 修复 ufw delete 'Could not delete non-existent rule' 警告 — 先检查规则是否存在再删除,消除无效警告输出 2. deploy-proxy.sh: PM2服务管理从 describe+delete+start 重构为 startOrRestart — 消除 '⚠️ PM2代理服务未完整注册' 每次update都出现的问题 — 统一 update() 和 restart() 函数的PM2逻辑 — 添加 --update-env 确保环境变量同步 3. ecosystem.proxy.config.js: 为三个代理服务添加 version: '1.0.0' — 消除 PM2 进程列表中版本显示 N/A 的问题 Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/c15b16e7-9f03-4f45-9c83-4e8fe1583aa6 Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> --- server/proxy/deploy-proxy.sh | 47 ++++++++++++++------------ server/proxy/ecosystem.proxy.config.js | 3 ++ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/server/proxy/deploy-proxy.sh b/server/proxy/deploy-proxy.sh index 7af19c6d..c332cb27 100644 --- a/server/proxy/deploy-proxy.sh +++ b/server/proxy/deploy-proxy.sh @@ -290,7 +290,10 @@ update() { ensure_log_permissions # 关闭3802外部端口 (订阅服务改为通过Nginx反代访问) - ufw delete allow 3802/tcp 2>/dev/null || true + if ufw status | grep -q "3802/tcp" 2>/dev/null; then + ufw delete allow 3802/tcp || true + echo " ✅ 已移除3802端口外部访问规则" + fi # 检查并修复443端口冲突 # 如果Nginx占用了443端口(旧SSL配置),需要移除以让Xray接管 @@ -313,19 +316,18 @@ update() { systemctl restart xray - # 检查PM2中是否已注册代理服务进程 - # 如果不存在则使用 ecosystem config 启动(而非仅 restart) - if pm2 describe zy-proxy-sub >/dev/null 2>&1 && \ - pm2 describe zy-proxy-monitor >/dev/null 2>&1 && \ - pm2 describe zy-proxy-guardian >/dev/null 2>&1; then - echo " PM2代理服务已存在,执行重启..." - pm2 restart zy-proxy-sub zy-proxy-monitor zy-proxy-guardian - else - echo " ⚠️ PM2代理服务未完整注册,执行启动..." - # 先删除可能存在的部分注册进程,然后重新启动全部 - pm2 delete zy-proxy-sub zy-proxy-monitor zy-proxy-guardian 2>/dev/null || true - start_pm2_services + # PM2代理服务: 使用 startOrRestart 统一处理(已注册→重启,未注册→启动) + cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; } + if [ -f "$PROXY_DIR/.env.keys" ]; then + set -a + # shellcheck source=/dev/null + source "$PROXY_DIR/.env.keys" + set +a fi + pm2 startOrRestart ecosystem.proxy.config.js --update-env + pm2 save + echo "✅ PM2代理服务已更新" + pm2 list health_check echo "✅ 更新完成" @@ -340,16 +342,17 @@ status() { restart() { echo "重启所有代理服务..." systemctl restart xray - # 检查PM2中是否已注册所有代理服务进程 - if pm2 describe zy-proxy-sub >/dev/null 2>&1 && \ - pm2 describe zy-proxy-monitor >/dev/null 2>&1 && \ - pm2 describe zy-proxy-guardian >/dev/null 2>&1; then - pm2 restart zy-proxy-sub zy-proxy-monitor zy-proxy-guardian - else - echo " ⚠️ PM2代理服务未完整注册,执行启动..." - pm2 delete zy-proxy-sub zy-proxy-monitor zy-proxy-guardian 2>/dev/null || true - start_pm2_services + # PM2代理服务: 使用 startOrRestart 统一处理 + cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; } + if [ -f "$PROXY_DIR/.env.keys" ]; then + set -a + # shellcheck source=/dev/null + source "$PROXY_DIR/.env.keys" + set +a fi + pm2 startOrRestart ecosystem.proxy.config.js --update-env + pm2 save + echo "✅ PM2代理服务已重启" sleep 3 health_check } diff --git a/server/proxy/ecosystem.proxy.config.js b/server/proxy/ecosystem.proxy.config.js index 93a8b2a3..39f68acd 100644 --- a/server/proxy/ecosystem.proxy.config.js +++ b/server/proxy/ecosystem.proxy.config.js @@ -7,6 +7,7 @@ module.exports = { apps: [ { name: 'zy-proxy-sub', + version: '1.0.0', script: '/opt/zhuyuan/proxy/service/subscription-server.js', instances: 1, env: { @@ -22,6 +23,7 @@ module.exports = { }, { name: 'zy-proxy-monitor', + version: '1.0.0', script: '/opt/zhuyuan/proxy/service/traffic-monitor.js', instances: 1, env: { @@ -35,6 +37,7 @@ module.exports = { }, { name: 'zy-proxy-guardian', + version: '1.0.0', script: '/opt/zhuyuan/proxy/service/proxy-guardian.js', instances: 1, env: { From 20800e877ed88cd1c7f99ec5bef044b9846b2418 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 08:42:55 +0000 Subject: [PATCH 2/2] =?UTF-8?q?refactor(proxy):=20=E6=8F=90=E5=8F=96PM2?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=80=BB=E8=BE=91=E5=88=B0=20start=5Fpm2=5Fs?= =?UTF-8?q?ervices()=20=E6=B6=88=E9=99=A4=E9=87=8D=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update() 和 restart() 共用 start_pm2_services() 函数, 该函数统一使用 pm2 startOrRestart --update-env 处理启动和重启。 Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/c15b16e7-9f03-4f45-9c83-4e8fe1583aa6 Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> --- server/proxy/deploy-proxy.sh | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/server/proxy/deploy-proxy.sh b/server/proxy/deploy-proxy.sh index c332cb27..c44d1c6c 100644 --- a/server/proxy/deploy-proxy.sh +++ b/server/proxy/deploy-proxy.sh @@ -223,7 +223,8 @@ configure_nginx() { fi } -# ── 启动PM2服务 ─────────────────────────────── +# ── 启动/重启PM2服务 ────────────────────────── +# 使用 pm2 startOrRestart 统一处理(已注册→重启,未注册→启动) start_pm2_services() { cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; } @@ -235,9 +236,9 @@ start_pm2_services() { set +a fi - pm2 start ecosystem.proxy.config.js + pm2 startOrRestart ecosystem.proxy.config.js --update-env pm2 save - echo "✅ PM2代理服务已启动" + echo "✅ PM2代理服务已就绪" pm2 list } @@ -316,18 +317,8 @@ update() { systemctl restart xray - # PM2代理服务: 使用 startOrRestart 统一处理(已注册→重启,未注册→启动) - cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; } - if [ -f "$PROXY_DIR/.env.keys" ]; then - set -a - # shellcheck source=/dev/null - source "$PROXY_DIR/.env.keys" - set +a - fi - pm2 startOrRestart ecosystem.proxy.config.js --update-env - pm2 save - echo "✅ PM2代理服务已更新" - pm2 list + # PM2代理服务 + start_pm2_services health_check echo "✅ 更新完成" @@ -342,17 +333,8 @@ status() { restart() { echo "重启所有代理服务..." systemctl restart xray - # PM2代理服务: 使用 startOrRestart 统一处理 - cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; } - if [ -f "$PROXY_DIR/.env.keys" ]; then - set -a - # shellcheck source=/dev/null - source "$PROXY_DIR/.env.keys" - set +a - fi - pm2 startOrRestart ecosystem.proxy.config.js --update-env - pm2 save - echo "✅ PM2代理服务已重启" + # PM2代理服务 + start_pm2_services sleep 3 health_check }