#!/usr/bin/env bash # 容器入口:迁移 → 启动自检 → api 与 worker 两个进程互相看护。 # 任一进程退出就停掉另一个并以非 0 退出,把"半死容器"变成整体退出,交给 restart 策略自愈。 set -euo pipefail BIN=/app/umt-server "$BIN" --role migrate "$BIN" --role preflight "$BIN" --role api & api_pid=$! "$BIN" --role worker & worker_pid=$! stop_all() { kill -TERM "$api_pid" "$worker_pid" 2>/dev/null || true wait "$api_pid" "$worker_pid" 2>/dev/null || true } on_signal() { echo "entrypoint: 收到 $1,停止 api 与 worker" >&2 stop_all exit 0 } trap 'on_signal SIGTERM' TERM trap 'on_signal SIGINT' INT set +e wait -n "$api_pid" "$worker_pid" code=$? set -e echo "entrypoint: 有进程退出(code=$code),停止其余进程" >&2 stop_all # 常驻进程不应自行正常退出;按失败处理以触发重启 if [ "$code" -eq 0 ]; then code=1; fi exit "$code"