Files
crypto_okx/deploy/pull_and_restart.sh
T
dekun a1abe159fa Initial standalone crypto_okx with one-click deploy.
Add deploy/manage.sh bootstrap for git.bz121.com/dekun/crypto_okx and point docs at this repo.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 20:00:59 +08:00

43 lines
921 B
Bash

#!/usr/bin/env bash
# 服务器上拉代码并重启 PM2.
# 用法(/opt/crypto_okx 下 root):
# bash deploy/pull_and_restart.sh
# bash deploy/pull_and_restart.sh --dry-run
set -e
set -u
if [ -n "${BASH_VERSION:-}" ]; then
set -o pipefail
fi
REPO="${REPO:-/opt/crypto_okx}"
PM2_APP_NAME="${PM2_APP_NAME:-crypto_okx}"
DRY=0
if [[ "${1:-}" == "--dry-run" ]]; then
DRY=1
echo "(dry-run mode)"
fi
cd "${REPO}"
echo ">>> git pull"
git pull
if [[ "${DRY}" -eq 1 ]]; then
echo "(dry-run, skip pm2 restart)"
exit 0
fi
echo ">>> pm2 restart ${PM2_APP_NAME} --update-env"
if command -v pm2 >/dev/null 2>&1; then
if pm2 pid "${PM2_APP_NAME}" >/dev/null 2>&1; then
pm2 restart "${PM2_APP_NAME}" --update-env
elif [[ -f ecosystem.config.cjs ]]; then
pm2 start ecosystem.config.cjs
else
echo "warn: 未找到 PM2 进程 ${PM2_APP_NAME}" >&2
fi
else
echo "warn: 未安装 pm2" >&2
fi
echo "done"