fix:优化启动脚本
This commit is contained in:
18
run.sh
18
run.sh
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# 部署流程:拉代码 → 安装依赖 → 构建前端到 dist/ → 后台启动后端 API(5599)
|
||||
# 部署流程:拉代码 → 安装依赖 → 构建前端到 dist/ →(可选)同步到 Nginx root → 后台启动 API(5599)
|
||||
# 若 Nginx 未反代 /api,请先设置 API_BASE_URL 再执行,例如:
|
||||
# export API_BASE_URL="http://你的域名或IP:5599"
|
||||
# ./run.sh
|
||||
# 使用 pm2 保活(推荐):export USE_PM2=1 && ./run.sh
|
||||
# 若项目在子目录、Nginx root 指向固定目录,构建后同步到该目录,例如:
|
||||
# export DEPLOY_DIST=/www/wwwroot/view.airtep.com/dist
|
||||
# ./run.sh
|
||||
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
@@ -21,6 +24,17 @@ fi
|
||||
|
||||
node build.js
|
||||
|
||||
# 若设置了 DEPLOY_DIST(与 Nginx root 一致),将 dist/ 同步到该目录以便访问
|
||||
if [ -n "$DEPLOY_DIST" ]; then
|
||||
mkdir -p "$DEPLOY_DIST"
|
||||
if command -v rsync >/dev/null 2>&1; then
|
||||
rsync -a --delete dist/ "$DEPLOY_DIST/"
|
||||
else
|
||||
(cd dist && find . -mindepth 1 -maxdepth 1 -exec cp -r {} "$DEPLOY_DIST/" \;)
|
||||
fi
|
||||
echo "[run.sh] 已同步 dist/ 到 $DEPLOY_DIST"
|
||||
fi
|
||||
|
||||
# 后台启动 API:优先 pm2,否则 nohup
|
||||
if [ -n "$USE_PM2" ] && command -v pm2 >/dev/null 2>&1; then
|
||||
echo "[run.sh] 使用 pm2 启动 API(端口 ${API_PORT})..."
|
||||
@@ -38,4 +52,4 @@ else
|
||||
exec bash start-api.sh
|
||||
fi
|
||||
|
||||
echo "[run.sh] 部署完成。前端静态在 dist/,API 端口 ${API_PORT}。检查: curl -s http://127.0.0.1:${API_PORT}/api/config"
|
||||
echo "[run.sh] 部署完成。前端静态在 dist/,API 端口 ${API_PORT}。检查: curl -s http://127.0.0.1:${API_PORT}/config"
|
||||
Reference in New Issue
Block a user