Files
loongyan/docker/entrypoint.sh
2026-03-25 14:35:01 +08:00

51 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# 关闭 set -e 才能执行最后的清理逻辑
set +e
# --- 1. 后端配置 ---
echo "Starting Dart backend on port 8081..."
export PORT=8081
# 确保数据目录存在(根据你之前的日志)
mkdir -p /app/data /app/cache
/app/bin/server &
BACKEND_PID=$!
# 等待后端稍微启动一下
sleep 2
# --- 2. 前端配置 ---
echo "Starting frontend on port 8080..."
export PORT=8080
export HOST=0.0.0.0
# 指向本地回环地址,因为前后端在同一个容器内
export BACKEND_URL=http://127.0.0.1:8081
cd /app/web/build
# 启动前端并放到后台
node index.js &
FRONTEND_PID=$!
# --- 3. 信号捕获 (修复了 SIGTERM 报错) ---
trap "echo 'Shutting down...'; kill $BACKEND_PID $FRONTEND_PID 2>/dev/null; exit 0" TERM INT
echo "Both services are running. Monitoring..."
# --- 4. 运行监控 ---
# 因为 sh 没有 wait -n我们用循环检查进程是否存在
while true; do
if ! kill -0 $BACKEND_PID 2>/dev/null; then
echo "Backend (Dart) exited unexpectedly."
break
fi
if ! kill -0 $FRONTEND_PID 2>/dev/null; then
echo "Frontend (Node.js) exited unexpectedly."
break
fi
sleep 2
done
# --- 5. 清理退出 ---
echo "Cleaning up processes..."
kill $BACKEND_PID $FRONTEND_PID 2>/dev/null || true
exit 1