e44cdf913e
Use npm ci/install in deploy script and docs to avoid frozen pnpm lockfile failures on the server. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
766 B
Bash
37 lines
766 B
Bash
#!/usr/bin/env bash
|
||
# 知命阁(zhimingge)Ubuntu 服务器更新脚本
|
||
# 用法:cd /opt/zhimingge && bash scripts/deploy.sh
|
||
|
||
set -euo pipefail
|
||
|
||
APP_DIR="/opt/zhimingge"
|
||
APP_NAME="zhimingge"
|
||
APP_PORT="${PORT:-3130}"
|
||
|
||
cd "$APP_DIR"
|
||
|
||
echo "==> 拉取最新代码..."
|
||
git pull origin main
|
||
|
||
echo "==> 安装依赖..."
|
||
npm ci || npm install
|
||
|
||
echo "==> 生产构建..."
|
||
npm run build
|
||
|
||
echo "==> 确保日志目录存在..."
|
||
mkdir -p logs
|
||
|
||
echo "==> 重启 PM2..."
|
||
if pm2 describe "$APP_NAME" > /dev/null 2>&1; then
|
||
pm2 restart "$APP_NAME"
|
||
else
|
||
pm2 start ecosystem.config.cjs
|
||
fi
|
||
|
||
pm2 save
|
||
|
||
echo "==> 部署完成,验证 http://127.0.0.1:${APP_PORT} ..."
|
||
pm2 status "$APP_NAME"
|
||
curl -s -o /dev/null -w "HTTP %{http_code}\n" "http://127.0.0.1:${APP_PORT}" || true
|