feat: 连通性检查加重试机制 + 新增 assets→issue 方向检查
- 两边检查均自带 3 次重试(间隔 10s),应对同时部署时目标容器暂不可达 - 新增 assets→issue API 连通性检查,与 issue→assets 对称
This commit is contained in:
parent
a7e0651bd5
commit
ccc0f5800d
52
deploy-ai.sh
52
deploy-ai.sh
|
|
@ -350,17 +350,27 @@ case "$SITE" in
|
||||||
ssh txjp "cp $REMOTE_DIR/../nginx-proxy-ai/conf.d/issue-ai.conf /root/docker/nginx-proxy-ai/conf.d/ 2>/dev/null || true
|
ssh txjp "cp $REMOTE_DIR/../nginx-proxy-ai/conf.d/issue-ai.conf /root/docker/nginx-proxy-ai/conf.d/ 2>/dev/null || true
|
||||||
docker exec nginx-ai nginx -s reload 2>/dev/null || true"
|
docker exec nginx-ai nginx -s reload 2>/dev/null || true"
|
||||||
|
|
||||||
# 验证 issue→assets API 连通性(确保 API Key 有效、网络可达)
|
# 验证 issue→assets API 连通性(带重试,应对同时部署时目标容器暂不可达)
|
||||||
info "检查 issue→assets API 连通性..."
|
info "检查 issue→assets API 连通性..."
|
||||||
ssh txjp 'cat > /tmp/check-conn.js' << 'CHECKEOF'
|
ssh txjp 'cat > /tmp/check-conn.js' << 'CHECKEOF'
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
const url = process.env.ASSETS_API_URL + "/assets?pageSize=1";
|
const url = process.env.ASSETS_API_URL + "/assets?pageSize=1";
|
||||||
const key = process.env.ASSETS_API_KEY || "";
|
const key = process.env.ASSETS_API_KEY || "";
|
||||||
|
let attempt = 0;
|
||||||
|
function tryConnect() {
|
||||||
|
attempt++;
|
||||||
http.get(url, {headers:{"Authorization":"Bearer "+key}}, (res) => {
|
http.get(url, {headers:{"Authorization":"Bearer "+key}}, (res) => {
|
||||||
if (res.statusCode === 200) { console.log("连通正常:", res.statusCode); process.exit(0); }
|
if (res.statusCode === 200) { console.log("连通正常: HTTP 200 (第"+attempt+"次)"); process.exit(0); }
|
||||||
console.error("连通失败: HTTP", res.statusCode, "(请检查 ASSETS_API_KEY 是否在 assets-ai 的 API Keys 中注册)");
|
console.error("连通失败: HTTP", res.statusCode, "(第"+attempt+"次)");
|
||||||
process.exit(1);
|
if (attempt < 3) { console.error("10s 后重试..."); setTimeout(tryConnect, 10000); }
|
||||||
}).on("error", (e) => { console.error("连通失败:", e.message); process.exit(1); });
|
else { console.error("已达最大重试次数,请检查 ASSETS_API_KEY 是否在 assets-ai 中注册"); process.exit(1); }
|
||||||
|
}).on("error", (e) => {
|
||||||
|
console.error("连接失败:", e.message, "(第"+attempt+"次)");
|
||||||
|
if (attempt < 3) { console.error("10s 后重试..."); setTimeout(tryConnect, 10000); }
|
||||||
|
else { console.error("已达最大重试次数"); process.exit(1); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
tryConnect();
|
||||||
CHECKEOF
|
CHECKEOF
|
||||||
CONN_CHECK=$(ssh txjp "docker cp /tmp/check-conn.js issue-ai:/tmp/check-conn.js && docker exec issue-ai sh -c 'cd /app && NODE_PATH=/app/node_modules node /tmp/check-conn.js'" 2>&1)
|
CONN_CHECK=$(ssh txjp "docker cp /tmp/check-conn.js issue-ai:/tmp/check-conn.js && docker exec issue-ai sh -c 'cd /app && NODE_PATH=/app/node_modules node /tmp/check-conn.js'" 2>&1)
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
|
@ -373,7 +383,37 @@ CHECKEOF
|
||||||
build_on_server || exit 1
|
build_on_server || exit 1
|
||||||
info "部署 nginx 路由..."
|
info "部署 nginx 路由..."
|
||||||
ssh txjp "cp $REMOTE_DIR/../nginx-proxy-ai/conf.d/assets-ai.conf /root/docker/nginx-proxy-ai/conf.d/ 2>/dev/null || true
|
ssh txjp "cp $REMOTE_DIR/../nginx-proxy-ai/conf.d/assets-ai.conf /root/docker/nginx-proxy-ai/conf.d/ 2>/dev/null || true
|
||||||
docker exec nginx-ai nginx -s reload 2>/dev/null || true" ;;
|
docker exec nginx-ai nginx -s reload 2>/dev/null || true"
|
||||||
|
|
||||||
|
# 验证 assets→issue API 连通性(带重试,应对同时部署时目标容器暂不可达)
|
||||||
|
info "检查 assets→issue API 连通性..."
|
||||||
|
ssh txjp 'cat > /tmp/check-conn.js' << 'CHECKEOF'
|
||||||
|
const http = require("http");
|
||||||
|
const url = process.env.ISSUE_API_URL + "/tickets?pageSize=1";
|
||||||
|
const key = process.env.ISSUE_API_KEY || "";
|
||||||
|
let attempt = 0;
|
||||||
|
function tryConnect() {
|
||||||
|
attempt++;
|
||||||
|
http.get(url, {headers:{"Authorization":"Bearer "+key}}, (res) => {
|
||||||
|
if (res.statusCode === 200) { console.log("连通正常: HTTP 200 (第"+attempt+"次)"); process.exit(0); }
|
||||||
|
console.error("连通失败: HTTP", res.statusCode, "(第"+attempt+"次)");
|
||||||
|
if (attempt < 3) { console.error("10s 后重试..."); setTimeout(tryConnect, 10000); }
|
||||||
|
else { console.error("已达最大重试次数,请检查 ISSUE_API_KEY 是否在 issue-ai 中注册"); process.exit(1); }
|
||||||
|
}).on("error", (e) => {
|
||||||
|
console.error("连接失败:", e.message, "(第"+attempt+"次)");
|
||||||
|
if (attempt < 3) { console.error("10s 后重试..."); setTimeout(tryConnect, 10000); }
|
||||||
|
else { console.error("已达最大重试次数"); process.exit(1); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
tryConnect();
|
||||||
|
CHECKEOF
|
||||||
|
CONN_CHECK=$(ssh txjp "docker cp /tmp/check-conn.js assets-ai:/tmp/check-conn.js && docker exec assets-ai sh -c 'cd /app && NODE_PATH=/app/node_modules node /tmp/check-conn.js'" 2>&1)
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
error "assets→issue API 连通性检查失败!请检查 ISSUE_API_KEY 是否在 issue-ai 中注册"
|
||||||
|
echo " $CONN_CHECK"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
log "assets→issue API 连通性正常" ;;
|
||||||
oa)
|
oa)
|
||||||
build_on_server || exit 1
|
build_on_server || exit 1
|
||||||
info "部署 nginx 配置..."
|
info "部署 nginx 配置..."
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue