You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
2.0 KiB

#!/bin/sh
# voitrans 容器入口:在一个容器内拉起 5 个集群服务,shell 监控进程。
#
# 运行时布局(宿主机挂 deploy/voitrans 目录为 /app,二进制在镜像内 /opt/voitrans):
# /app/ ← 宿主机 deploy/voitrans 目录
# ├── confs/*.yaml ← 各服务配置(gateway/home/api/mcp/timer)
# ├── log/ ← 日志输出
# └── ... ← 其他运行期资源(密钥/词库等,如有)
# /opt/voitrans/a11/*.a11 ← 镜像内二进制
#
# cwd=/app,所以配置里的相对路径 ./confs/... ./log/... 均直接生效。
# 任一服务进程退出 → 杀掉其余 → 容器退出码 1 → docker 按 restart 策略整体拉起。
set -e
cd /app
A11=/opt/voitrans/a11
echo "[entrypoint] starting voitrans services..."
# gateway 是 HTTP 入口 + 服务发现枢纽,先起;home/api/timer 随后;mcp 依赖 gateway 发现,最后起。
${A11}/gateway.a11 -conf ./confs/gateway.yaml & PID_GW=$!
${A11}/home.a11 -conf ./confs/home.yaml & PID_HOME=$!
${A11}/api.a11 -conf ./confs/api.yaml & PID_API=$!
${A11}/timer.a11 -conf ./confs/timer.yaml & PID_TIMER=$!
# mcp 依赖 gateway 的服务发现,稍等再起
sleep 3
${A11}/mcp.a11 -conf ./confs/mcp.yaml & PID_MCP=$!
echo "[entrypoint] gateway=$PID_GW home=$PID_HOME api=$PID_API timer=$PID_TIMER mcp=$PID_MCP"
ALL_PIDS="$PID_GW $PID_HOME $PID_API $PID_TIMER $PID_MCP"
shutdown() {
echo "[entrypoint] received shutdown signal, stopping services..."
kill -TERM $ALL_PIDS 2>/dev/null || true
wait
echo "[entrypoint] all services stopped, exiting"
exit 0
}
trap shutdown TERM INT
# 守护:任一进程消失即整体退出(交给 docker restart)
while :; do
for pid in $ALL_PIDS; do
if ! kill -0 "$pid" 2>/dev/null; then
echo "[entrypoint] FATAL: pid $pid exited, shutting down container"
kill -TERM $ALL_PIDS 2>/dev/null || true
wait
exit 1
fi
done
sleep 2
done