#!/bin/sh # 供 yh_nginx 容器:在官方 entrypoint 之前等待 Compose/Podman 网络内 web/admin/api 可访问。 # 解决 1) 启动瞬间 host not found;2) Podman 无 127.0.0.11 时勿用 resolver+变量 proxy_pass(否则 502/超时)。 set -e MAX="${NGINX_WAIT_UPSTREAM_SEC:-90}" echo "yh_nginx: waiting for upstream (web:80 admin:80 api:8088), max ${MAX}s..." # 优先 HTTP 探测(ICMP 在部分环境被禁);无 wget 时用 ping ping_one() { host="$1" if ping -c1 -W2 "$host" >/dev/null 2>&1; then return 0 fi ping -c1 -w3 "$host" >/dev/null 2>&1 } upstream_ok() { host="$1" port="$2" path="${3:-/}" if command -v wget >/dev/null 2>&1; then wget -q -O/dev/null -T 3 "http://${host}:${port}${path}" 2>/dev/null && return 0 fi ping_one "$host" } n=0 while [ "$n" -lt "$MAX" ]; do # api 根路径常为 404,用 /api/health(与 yuheng.docker.conf 注释一致) if upstream_ok web 80 / && upstream_ok admin 80 / && upstream_ok api 8088 /api/health; then echo "yh_nginx: upstream OK, starting nginx..." exec /docker-entrypoint.sh nginx -g 'daemon off;' fi n=$((n + 1)) sleep 1 done echo "yh_nginx: timeout waiting for web/admin/api (check 容器是否在同一网络、api 是否监听 8088)" >&2 exit 1