Files
eth_hedge_sim/deploy/pull_and_restart.sh
T
2026-07-24 16:41:31 +08:00

51 lines
1.4 KiB
Bash

#!/usr/bin/env bash
# 一键更新/部署:仅 git pull,禁止 scp 传代码。
# 用法(服务器上): bash /opt/eth_hedge_sim/deploy/pull_and_restart.sh
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
echo "[eth_hedge_sim] pull @ $ROOT"
git fetch --all --prune
git pull --ff-only
if [[ ! -f "$ROOT/.env" ]]; then
echo "[eth_hedge_sim] missing .env — copy from example"
cp "$ROOT/.env.example" "$ROOT/.env"
# 云上测试机默认直连 OKX
sed -i 's/^OKX_HTTP_PROXY=.*/OKX_HTTP_PROXY=/' "$ROOT/.env" || true
sed -i 's/^API_PORT=.*/API_PORT=5155/' "$ROOT/.env" || true
sed -i 's/^ENV_NAME=.*/ENV_NAME=test/' "$ROOT/.env" || true
echo "[eth_hedge_sim] wrote .env — please review AUTH_* secrets"
fi
if [[ ! -d "$ROOT/.venv" ]]; then
python3 -m venv "$ROOT/.venv"
fi
# shellcheck disable=SC1091
source "$ROOT/.venv/bin/activate"
pip install -U pip
pip install -r "$ROOT/requirements.txt"
if ! command -v npm >/dev/null 2>&1; then
echo "ERROR: npm not found. Install Node.js 18+ first."
exit 1
fi
(
cd "$ROOT/frontend"
if [[ -f package-lock.json ]]; then npm ci; else npm install; fi
npm run build
)
if ! command -v pm2 >/dev/null 2>&1; then
npm install -g pm2
fi
# 仅 reload 本项目进程,禁止 pm2 restart all
pm2 startOrReload "$ROOT/deploy/ecosystem.config.cjs" --update-env
pm2 save
echo "[eth_hedge_sim] done. health: http://127.0.0.1:5155/health public: https://dc.hyf2.cc/health"