fix(proxy): 修复铸渊专线部署3个问题 — ufw警告抑制、PM2服务管理重构(startOrRestart)、版本号N/A

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>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-04 08:40:54 +00:00 committed by GitHub
parent c9b6e31359
commit 59ce18c1c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 22 deletions

View File

@ -290,7 +290,10 @@ update() {
ensure_log_permissions ensure_log_permissions
# 关闭3802外部端口 (订阅服务改为通过Nginx反代访问) # 关闭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端口冲突 # 检查并修复443端口冲突
# 如果Nginx占用了443端口(旧SSL配置),需要移除以让Xray接管 # 如果Nginx占用了443端口(旧SSL配置),需要移除以让Xray接管
@ -313,19 +316,18 @@ update() {
systemctl restart xray systemctl restart xray
# 检查PM2中是否已注册代理服务进程 # PM2代理服务: 使用 startOrRestart 统一处理(已注册→重启,未注册→启动)
# 如果不存在则使用 ecosystem config 启动(而非仅 restart) cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; }
if pm2 describe zy-proxy-sub >/dev/null 2>&1 && \ if [ -f "$PROXY_DIR/.env.keys" ]; then
pm2 describe zy-proxy-monitor >/dev/null 2>&1 && \ set -a
pm2 describe zy-proxy-guardian >/dev/null 2>&1; then # shellcheck source=/dev/null
echo " PM2代理服务已存在,执行重启..." source "$PROXY_DIR/.env.keys"
pm2 restart zy-proxy-sub zy-proxy-monitor zy-proxy-guardian set +a
else
echo " ⚠️ PM2代理服务未完整注册,执行启动..."
# 先删除可能存在的部分注册进程,然后重新启动全部
pm2 delete zy-proxy-sub zy-proxy-monitor zy-proxy-guardian 2>/dev/null || true
start_pm2_services
fi fi
pm2 startOrRestart ecosystem.proxy.config.js --update-env
pm2 save
echo "✅ PM2代理服务已更新"
pm2 list
health_check health_check
echo "✅ 更新完成" echo "✅ 更新完成"
@ -340,16 +342,17 @@ status() {
restart() { restart() {
echo "重启所有代理服务..." echo "重启所有代理服务..."
systemctl restart xray systemctl restart xray
# 检查PM2中是否已注册所有代理服务进程 # PM2代理服务: 使用 startOrRestart 统一处理
if pm2 describe zy-proxy-sub >/dev/null 2>&1 && \ cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; }
pm2 describe zy-proxy-monitor >/dev/null 2>&1 && \ if [ -f "$PROXY_DIR/.env.keys" ]; then
pm2 describe zy-proxy-guardian >/dev/null 2>&1; then set -a
pm2 restart zy-proxy-sub zy-proxy-monitor zy-proxy-guardian # shellcheck source=/dev/null
else source "$PROXY_DIR/.env.keys"
echo " ⚠️ PM2代理服务未完整注册,执行启动..." set +a
pm2 delete zy-proxy-sub zy-proxy-monitor zy-proxy-guardian 2>/dev/null || true
start_pm2_services
fi fi
pm2 startOrRestart ecosystem.proxy.config.js --update-env
pm2 save
echo "✅ PM2代理服务已重启"
sleep 3 sleep 3
health_check health_check
} }

View File

@ -7,6 +7,7 @@ module.exports = {
apps: [ apps: [
{ {
name: 'zy-proxy-sub', name: 'zy-proxy-sub',
version: '1.0.0',
script: '/opt/zhuyuan/proxy/service/subscription-server.js', script: '/opt/zhuyuan/proxy/service/subscription-server.js',
instances: 1, instances: 1,
env: { env: {
@ -22,6 +23,7 @@ module.exports = {
}, },
{ {
name: 'zy-proxy-monitor', name: 'zy-proxy-monitor',
version: '1.0.0',
script: '/opt/zhuyuan/proxy/service/traffic-monitor.js', script: '/opt/zhuyuan/proxy/service/traffic-monitor.js',
instances: 1, instances: 1,
env: { env: {
@ -35,6 +37,7 @@ module.exports = {
}, },
{ {
name: 'zy-proxy-guardian', name: 'zy-proxy-guardian',
version: '1.0.0',
script: '/opt/zhuyuan/proxy/service/proxy-guardian.js', script: '/opt/zhuyuan/proxy/service/proxy-guardian.js',
instances: 1, instances: 1,
env: { env: {