Merge pull request #243 from qinfendebingshuo/copilot/global-check-repair

Fix CN relay: Nginx silent start failure + add subscription auto-failover
This commit is contained in:
冰朔 2026-03-31 21:06:23 +08:00 committed by GitHub
commit 46f0eb6754
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 108 additions and 17 deletions

View File

@ -287,16 +287,36 @@ jobs:
# 通过SG跳板验证CN中转服务状态
echo "🔍 通过SG跳板验证CN中转..."
ssh cn-target "
VERIFY_RESULT=$(ssh cn-target "
FAIL=0
echo '§1 Nginx状态:'
systemctl is-active nginx && echo ' ✅ Nginx运行中' || echo ' ❌ Nginx未运行'
if systemctl is-active --quiet nginx; then
echo ' ✅ Nginx运行中'
else
echo ' ❌ Nginx未运行'
FAIL=1
fi
echo '§2 中转端口 2053:'
ss -tlnp | grep -q ':2053 ' && echo ' ✅ 端口2053监听中' || echo ' ⚠️ 端口2053未监听'
if ss -tlnp | grep -q ':2053'; then
echo ' ✅ 端口2053监听中'
else
echo ' ❌ 端口2053未监听'
FAIL=1
fi
echo '§3 HTTP健康检查:'
curl -sf http://127.0.0.1/health 2>/dev/null && echo ' ✅ HTTP健康检查正常' || echo ' ⚠️ HTTP健康检查未响应'
"
if curl -sf http://127.0.0.1/health >/dev/null 2>&1; then
echo ' ✅ HTTP健康检查正常'
else
echo ' ⚠️ HTTP健康检查未响应'
fi
exit \$FAIL
" 2>&1) && CN_OK=true || CN_OK=false
echo "$VERIFY_RESULT"
# 从外部验证CN HTTP (GitHub Actions可以通过HTTP访问中国服务器)
CN_HOST="${{ secrets.ZY_CN_SERVER_HOST }}"
@ -307,6 +327,14 @@ jobs:
echo "⚠️ CN HTTP外部检查: 状态码 $HTTP_CODE (可能需要等待或在防火墙开放80端口)"
fi
# 关键服务必须运行
if [ "$CN_OK" = "false" ]; then
echo ""
echo "❌ CN中转关键服务未就绪 (Nginx未运行或端口2053未监听)"
echo " 请检查CN服务器Nginx状态和腾讯云安全组2053端口"
exit 1
fi
- name: '🧹 清理SSH密钥'
if: always()
run: rm -f ~/.ssh/id_sg ~/.ssh/id_cn ~/.ssh/config

View File

@ -167,14 +167,37 @@ function generateClashYaml(keys, serverHost) {
client-fingerprint: chrome` : '';
// 代理组中的节点列表
// SG直连优先 (更可靠的直连节点排在前面作为默认)
const proxyList = cnRelayHost
? ` - "🇨🇳 铸渊专线-CN中转"
- "🏛️ 铸渊专线-SG直连"`
? ` - "🏛️ 铸渊专线-SG直连"
- "🇨🇳 铸渊专线-CN中转"`
: ' - "🏛️ 铸渊专线-SG直连"';
const proxyListWithDirect = cnRelayHost
? ` - "🇨🇳 铸渊专线-CN中转"
? ` - "🏛️ 铸渊专线-SG直连"
- "🇨🇳 铸渊专线-CN中转"
- DIRECT`
: ` - "🏛️ 铸渊专线-SG直连"
- DIRECT`;
// 自动选择组 (url-test: 自动测试延迟,选择最快可用节点)
// CN中转如果不可用(connection refused)会自动被排除
const autoGroupBlock = cnRelayHost ? `
- name: "♻️ 自动选择"
type: url-test
proxies:
- "🏛️ 铸渊专线-SG直连"
- "🇨🇳 铸渊专线-CN中转"
url: "http://www.gstatic.com/generate_204"
interval: 300
tolerance: 50
` : '';
// 主代理组: 有CN时默认使用自动选择无CN时直接使用SG
const mainGroupProxies = cnRelayHost
? ` - "♻️ 自动选择"
- "🏛️ 铸渊专线-SG直连"
- "🇨🇳 铸渊专线-CN中转"
- DIRECT`
: ` - "🏛️ 铸渊专线-SG直连"
- DIRECT`;
@ -211,8 +234,8 @@ proxy-groups:
- name: "🌐 铸渊专线"
type: select
proxies:
${proxyListWithDirect}
${mainGroupProxies}
${autoGroupBlock}
- name: "🤖 AI服务"
type: select
proxies:

View File

@ -279,8 +279,21 @@ log_step "§5 测试并应用配置"
NGINX_TEST_OUTPUT=$(nginx -t 2>&1)
if echo "$NGINX_TEST_OUTPUT" | grep -q "test is successful"; then
systemctl reload nginx
log_info "✅ Nginx配置测试通过 · 已重载"
# reload 只能用于已运行的Nginx如果Nginx未运行则需要 start
if systemctl is-active --quiet nginx; then
systemctl reload nginx
log_info "✅ Nginx配置测试通过 · 已重载"
else
systemctl enable nginx 2>/dev/null || true
systemctl start nginx
if systemctl is-active --quiet nginx; then
log_info "✅ Nginx配置测试通过 · 已启动"
else
log_error "Nginx启动失败"
systemctl status nginx --no-pager 2>&1 || true
exit 1
fi
fi
else
log_warn "Nginx配置测试未通过尝试自动修复..."
echo "$NGINX_TEST_OUTPUT"
@ -299,8 +312,14 @@ else
# 重新测试
if nginx -t 2>&1; then
systemctl reload nginx
log_info "✅ 自动修复成功 · Nginx已重载"
if systemctl is-active --quiet nginx; then
systemctl reload nginx
log_info "✅ 自动修复成功 · Nginx已重载"
else
systemctl enable nginx 2>/dev/null || true
systemctl start nginx
log_info "✅ 自动修复成功 · Nginx已启动"
fi
else
log_error "Nginx配置测试失败 (自动修复未能解决)"
nginx -t 2>&1
@ -337,18 +356,39 @@ log_step "§7 健康检查"
sleep 1
# 确认Nginx真正在运行
if ! systemctl is-active --quiet nginx; then
log_warn "Nginx未运行尝试启动..."
systemctl enable nginx 2>/dev/null || true
systemctl start nginx
sleep 2
fi
HEALTH_OK=true
# 检查中转端口
if ss -tlnp | grep -q ":${RELAY_PORT} "; then
if ss -tlnp | grep -q ":${RELAY_PORT}[[:space:]]"; then
log_info "✅ 中转端口 ${RELAY_PORT}: 监听中"
else
log_warn "中转端口 ${RELAY_PORT}: 未监听 (可能需要等待)"
log_error "中转端口 ${RELAY_PORT}: 未监听"
HEALTH_OK=false
fi
# 检查HTTP
if curl -sf http://127.0.0.1/health >/dev/null 2>&1; then
log_info "✅ HTTP健康检查: 正常"
else
log_warn "HTTP健康检查: 未响应"
log_warn "HTTP健康检查: 未响应 (可能80端口被占用)"
fi
# 如果关键端口未监听报告Nginx状态用于调试
if [ "$HEALTH_OK" = "false" ]; then
log_error "关键服务未就绪 · Nginx诊断信息:"
systemctl status nginx --no-pager 2>&1 || true
echo ""
echo "Nginx错误日志 (最后10行):"
tail -10 /var/log/nginx/error.log 2>/dev/null || echo " (无日志)"
exit 1
fi
echo ""