#!/usr/bin/env sh set -eu # docker compose run 传入命令时直接执行,例如 migrate-mysql 的迁移脚本。 if [ "$#" -gt 0 ]; then exec "$@" fi echo "正在执行数据库迁移..." python -c 'from web.backend.database import run_migrations; run_migrations()' echo "数据库迁移完成" # 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