Files
PolyHermes/docker/start.sh
T
WrBug f33f03a4a8 fix: 使用 root 用户启动 Nginx,后端应用以 appuser 运行
- Nginx 以 root 用户运行(解决 80 端口绑定权限问题)
- 后端应用以 appuser 用户运行(保持安全性)
- 移除 setcap 相关配置(不再需要)
- 更新目录权限设置(Nginx 相关目录使用 root,应用目录使用 appuser)
2025-12-03 05:34:26 +08:00

43 lines
990 B
Bash
Executable File

#!/bin/bash
# 启动脚本:同时启动 Nginx 和后端服务
set -e
# 函数:清理进程
cleanup() {
echo "收到退出信号,清理进程..."
if [ -n "$BACKEND_PID" ]; then
kill $BACKEND_PID 2>/dev/null || true
fi
nginx -s quit 2>/dev/null || true
exit 0
}
# 注册信号处理
trap cleanup SIGTERM SIGINT
# 启动后端服务(以 appuser 用户运行,后台运行)
echo "启动后端服务..."
su appuser -c "cd /app && java -jar /app/app.jar --spring.profiles.active=${SPRING_PROFILES_ACTIVE:-prod}" &
BACKEND_PID=$!
# 等待后端服务启动
echo "等待后端服务启动..."
for i in {1..60}; do
if curl -f http://localhost:8000/api/health > /dev/null 2>&1; then
echo "后端服务已启动"
break
fi
if [ $i -eq 60 ]; then
echo "后端服务启动超时"
exit 1
fi
sleep 1
done
# 启动 Nginx(前台运行,作为主进程)
echo "启动 Nginx..."
exec nginx -g "daemon off;"