refactor(proxy): 提取PM2管理逻辑到 start_pm2_services() 消除重复代码
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>
This commit is contained in:
parent
59ce18c1c5
commit
20800e877e
|
|
@ -223,7 +223,8 @@ configure_nginx() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── 启动PM2服务 ───────────────────────────────
|
# ── 启动/重启PM2服务 ──────────────────────────
|
||||||
|
# 使用 pm2 startOrRestart 统一处理(已注册→重启,未注册→启动)
|
||||||
start_pm2_services() {
|
start_pm2_services() {
|
||||||
cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; }
|
cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; }
|
||||||
|
|
||||||
|
|
@ -235,9 +236,9 @@ start_pm2_services() {
|
||||||
set +a
|
set +a
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pm2 start ecosystem.proxy.config.js
|
pm2 startOrRestart ecosystem.proxy.config.js --update-env
|
||||||
pm2 save
|
pm2 save
|
||||||
echo "✅ PM2代理服务已启动"
|
echo "✅ PM2代理服务已就绪"
|
||||||
pm2 list
|
pm2 list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,18 +317,8 @@ update() {
|
||||||
|
|
||||||
systemctl restart xray
|
systemctl restart xray
|
||||||
|
|
||||||
# PM2代理服务: 使用 startOrRestart 统一处理(已注册→重启,未注册→启动)
|
# PM2代理服务
|
||||||
cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; }
|
start_pm2_services
|
||||||
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
|
health_check
|
||||||
echo "✅ 更新完成"
|
echo "✅ 更新完成"
|
||||||
|
|
@ -342,17 +333,8 @@ status() {
|
||||||
restart() {
|
restart() {
|
||||||
echo "重启所有代理服务..."
|
echo "重启所有代理服务..."
|
||||||
systemctl restart xray
|
systemctl restart xray
|
||||||
# PM2代理服务: 使用 startOrRestart 统一处理
|
# PM2代理服务
|
||||||
cd "$PROXY_DIR" || { echo "❌ 无法进入 $PROXY_DIR"; return 1; }
|
start_pm2_services
|
||||||
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
|
sleep 3
|
||||||
health_check
|
health_check
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue