Files
live-hub-py/docker-entrypoint.sh
T
2026-08-12 17:59:26 +08:00

48 lines
1.3 KiB
Bash

#!/usr/bin/env sh
set -eu
# docker compose run 传入命令时直接执行,例如 migrate-mysql 的迁移脚本。
if [ "$#" -gt 0 ]; then
exec "$@"
fi
# Worker 仅监听容器回环地址,Web 后端通过 127.0.0.1 调用。
python /app/services/yyb-worker/runtime/scripts/yyb-worker.py \
--host 127.0.0.1 \
--port 8810 \
--data-dir /app/data/yyb-worker-jobs &
worker_pid=$!
web_pid=""
stop_processes() {
kill -TERM "$worker_pid" 2>/dev/null || true
if [ -n "$web_pid" ]; then
kill -TERM "$web_pid" 2>/dev/null || true
fi
wait "$worker_pid" 2>/dev/null || true
if [ -n "$web_pid" ]; then
wait "$web_pid" 2>/dev/null || true
fi
}
trap stop_processes INT TERM
python -m uvicorn web.backend.main:app --host 0.0.0.0 --port 8800 --workers 1 &
web_pid=$!
while :; do
if ! kill -0 "$worker_pid" 2>/dev/null; then
if wait "$worker_pid"; then exit_code=0; else exit_code=$?; fi
kill -TERM "$web_pid" 2>/dev/null || true
wait "$web_pid" 2>/dev/null || true
exit "$exit_code"
fi
if ! kill -0 "$web_pid" 2>/dev/null; then
if wait "$web_pid"; then exit_code=0; else exit_code=$?; fi
kill -TERM "$worker_pid" 2>/dev/null || true
wait "$worker_pid" 2>/dev/null || true
exit "$exit_code"
fi
sleep 1
done