fix: 修复启动脚本不正确的问题

This commit is contained in:
Daniel
2026-03-08 17:37:02 +08:00
parent 06c0e36d92
commit 2dd1117e51
2 changed files with 24 additions and 7 deletions

15
run.sh
View File

@@ -10,6 +10,7 @@
set -e
cd "$(dirname "$0")"
ROOT="$(pwd)"
API_PORT="${PORT:-5599}"
export PORT="$API_PORT"
@@ -54,21 +55,21 @@ _kill_port() {
}
_kill_port
# 后台启动 API优先 pm2否则 nohup
# 后台启动 API优先 pm2否则 nohupROOT 与 PORT 已在上方定义)
if [ -n "$USE_PM2" ] && command -v pm2 >/dev/null 2>&1; then
echo "[run.sh] 使用 pm2 启动 API端口 ${API_PORT}..."
(cd server && npm install --no-audit --no-fund --silent && pm2 delete view-airtep-api 2>/dev/null; true)
(cd server && pm2 start index.js --name view-airtep-api)
(cd "$ROOT/server" && npm install --no-audit --no-fund --silent && pm2 delete view-airtep-api 2>/dev/null; true)
(cd "$ROOT/server" && PORT="$API_PORT" pm2 start index.js --name view-airtep-api)
pm2 save 2>/dev/null || true
echo "[run.sh] API 已由 pm2 托管。查看: pm2 list / pm2 logs view-airtep-api"
elif command -v nohup >/dev/null 2>&1; then
echo "[run.sh] 使用 nohup 后台启动 API端口 ${API_PORT}..."
mkdir -p logs
nohup bash start-api.sh >> logs/api.log 2>&1 &
echo "[run.sh] API 已在后台运行。查看日志: tail -f logs/api.log"
mkdir -p "$ROOT/logs"
nohup bash "$ROOT/start-api.sh" >> "$ROOT/logs/api.log" 2>&1 &
echo "[run.sh] API 已在后台运行。查看日志: tail -f $ROOT/logs/api.log"
else
echo "[run.sh] 前台启动 APICtrl+C 会停止服务)..."
exec bash start-api.sh
exec bash "$ROOT/start-api.sh"
fi
echo "[run.sh] 部署完成。前端静态在 dist/API 端口 ${API_PORT}"