Support up to 3 strategy slots on one host with auto ports.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-01 23:33:41 +08:00
parent 9c515644a3
commit aab0b9bdf6
8 changed files with 503 additions and 200 deletions
+32 -11
View File
@@ -2,41 +2,57 @@
# 一键更新/部署:仅 git pull,禁止 scp 传代码。
# 用法:
# bash /opt/eth_hedge_sim/deploy/pull_and_restart.sh
# 或通过 manage.sh 选 1/3
# bash /opt/eth_hedge_sim_2/deploy/pull_and_restart.sh
# 或通过 manage.sh 选槽位后部署/更新
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
# 有 root 时:检测 Python / Node / PM2,缺则装、有则跳过(pull 前用当前脚本)
if [[ -f "$ROOT/deploy/lib/common.sh" ]] && [[ "$(id -u)" -eq 0 ]]; then
_COMMON="$ROOT/deploy/lib/common.sh"
if [[ -f "$_COMMON" ]]; then
# shellcheck source=lib/common.sh
source "$ROOT/deploy/lib/common.sh"
source "$_COMMON"
apply_slot_for_root "$ROOT"
fi
# 有 root 时:检测 Python / Node / PM2,缺则装、有则跳过(pull 前用当前脚本)
if [[ -f "$_COMMON" ]] && [[ "$(id -u)" -eq 0 ]]; then
ensure_system_deps
fi
echo "[比特骆驼] pull @ $ROOT"
echo "[比特骆驼] pull @ $ROOT (slot=${INSTANCE_SLOT:-?} port=${API_PORT:-?})"
if [[ -d "$ROOT/.git" ]]; then
git fetch --all --prune
git pull --ff-only
fi
# pull 后再检测一次,确保用上仓库里最新的 python3-venv / ensurepip 逻辑
if [[ -f "$ROOT/deploy/lib/common.sh" ]] && [[ "$(id -u)" -eq 0 ]]; then
if [[ -f "$_COMMON" ]]; then
# shellcheck source=lib/common.sh
source "$ROOT/deploy/lib/common.sh"
source "$_COMMON"
apply_slot_for_root "$ROOT"
fi
if [[ -f "$_COMMON" ]] && [[ "$(id -u)" -eq 0 ]]; then
ensure_system_deps
fi
if [[ ! -f "$ROOT/.env" ]]; then
echo "[比特骆驼] missing .env — copy from example"
cp "$ROOT/.env.example" "$ROOT/.env"
# 云上测试机默认直连 OKX
# 云上测试机默认直连 OKX;端口按槽位
local_port="${API_PORT:-5155}"
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/^API_PORT=.*/API_PORT=${local_port}/" "$ROOT/.env" || true
sed -i 's/^ENV_NAME=.*/ENV_NAME=test/' "$ROOT/.env" || true
sed -i 's/^EXCHANGE=.*/EXCHANGE=okx/' "$ROOT/.env" || true
echo "[比特骆驼] wrote .env — please review AUTH_* secrets"
if [[ -f "$_COMMON" ]]; then
secret="$(random_auth_secret)"
if [[ -n "${secret}" ]]; then
sed -i "s/^AUTH_SECRET=.*/AUTH_SECRET=${secret}/" "$ROOT/.env" || true
fi
fi
echo "[比特骆驼] wrote .env — API_PORT=${local_port};请按需修改 AUTH_*"
fi
if ! command -v python3 >/dev/null 2>&1; then
@@ -93,8 +109,13 @@ else
echo "[比特骆驼] pm2 already present, skip install"
fi
# 按本目录槽位重写 PM2 配置(避免 git pull 盖回槽位 1 硬编码)
if [[ -f "$_COMMON" ]]; then
write_ecosystem_config "$ROOT" "${PM2_APP_NAME}" "${API_PORT}"
fi
# 仅 reload 本项目进程,禁止 pm2 restart all
pm2 startOrReload "$ROOT/deploy/ecosystem.config.cjs" --update-env
pm2 save
echo "[比特骆驼] done. health: http://127.0.0.1:5155/health"
echo "[比特骆驼] done. slot=${INSTANCE_SLOT:-1} health: http://127.0.0.1:${API_PORT:-5155}/health"