fix: wait for stunnel before starting
This commit is contained in:
parent
67b8cac467
commit
60a2490e86
@ -31,7 +31,7 @@ server:
|
||||
|
||||
store:
|
||||
driver: "postgres"
|
||||
dsn: "postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
dsn: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
maxOpenConns: 30
|
||||
maxIdleConns: 10
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ spec:
|
||||
containers:
|
||||
# --- 主应用容器 ---
|
||||
- name: accounts-api
|
||||
image: asia-northeast1-docker.pkg.dev/xzerolab-480008/cloud-run-source-deploy/accounts.svc.plus/accounts-svc-plus:latest
|
||||
image: asia-northeast1-docker.pkg.dev/xzerolab-480008/cloud-run-source-deploy/accounts.svc.plus/accounts-svc-plus:217c617b25328b3529ba2ec983d5a4f71849cf30
|
||||
ports:
|
||||
- name: http1
|
||||
containerPort: 8080
|
||||
@ -32,7 +32,12 @@ spec:
|
||||
- name: DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: admin_password
|
||||
name: postgres-password
|
||||
key: latest
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-password
|
||||
key: latest
|
||||
- name: DB_HOST
|
||||
value: "127.0.0.1"
|
||||
@ -40,6 +45,8 @@ spec:
|
||||
value: "15432"
|
||||
- name: DB_USER
|
||||
value: postgres
|
||||
- name: POSTGRES_USER
|
||||
value: postgres
|
||||
- name: DB_NAME
|
||||
value: postgres
|
||||
resources:
|
||||
|
||||
@ -31,4 +31,21 @@ if [ -n "${PORT:-}" ]; then
|
||||
CONFIG_FILE="${tmp_cfg}"
|
||||
fi
|
||||
|
||||
if [ -n "${DB_HOST:-}" ] && [ -n "${DB_PORT:-}" ]; then
|
||||
if [ "${DB_HOST}" = "127.0.0.1" ] || [ "${DB_HOST}" = "localhost" ]; then
|
||||
if command -v nc >/dev/null; then
|
||||
wait_seconds="${STUNNEL_WAIT_SECONDS:-30}"
|
||||
i=0
|
||||
while ! nc -z "${DB_HOST}" "${DB_PORT}" >/dev/null 2>&1; do
|
||||
i=$((i + 1))
|
||||
if [ "${i}" -ge "${wait_seconds}" ]; then
|
||||
echo "stunnel not ready after ${wait_seconds}s on ${DB_HOST}:${DB_PORT}" >&2
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
exec /usr/local/bin/account --config "${CONFIG_FILE}" "$@"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user