Support up to 3 strategy slots on one host with auto ports.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+18
-6
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# deploy/lib/install.sh — 一键部署策略机
|
||||
# deploy/lib/install.sh — 一键部署策略机(支持槽位 1/2/3)
|
||||
set -e
|
||||
set -u
|
||||
if [ -n "${BASH_VERSION:-}" ]; then
|
||||
@@ -13,10 +13,12 @@ source "${LIB_DIR}/common.sh"
|
||||
run_pipeline() {
|
||||
local root="$1"
|
||||
REPO_ROOT="${root}"
|
||||
step "构建并启动策略机 (pull_and_restart.sh)"
|
||||
INSTALL_ROOT="${root}"
|
||||
apply_slot_for_root "${root}"
|
||||
step "构建并启动策略机 (pull_and_restart.sh) slot=${INSTANCE_SLOT}"
|
||||
bash "${REPO_ROOT}/deploy/pull_and_restart.sh"
|
||||
pm2_save_startup
|
||||
verify_health || true
|
||||
verify_health "${API_PORT}" || true
|
||||
print_post_install_guide
|
||||
}
|
||||
|
||||
@@ -24,7 +26,8 @@ install_fresh() {
|
||||
require_root
|
||||
step "一键部署策略机 — 环境检测与依赖"
|
||||
ensure_system_deps
|
||||
step "克隆仓库 → ${INSTALL_ROOT}"
|
||||
assert_port_free_for_install "${API_PORT}" "${PM2_APP_NAME}"
|
||||
step "克隆仓库 → ${INSTALL_ROOT}(槽位 ${INSTANCE_SLOT} / :${API_PORT})"
|
||||
if [[ -d "${INSTALL_ROOT}" ]]; then
|
||||
die "目录已存在: ${INSTALL_ROOT},请先卸载或选修复"
|
||||
fi
|
||||
@@ -40,13 +43,13 @@ install_repair() {
|
||||
if ! REPO_ROOT="$(resolve_repo_root)"; then
|
||||
die "未找到安装目录 ${INSTALL_ROOT}"
|
||||
fi
|
||||
step "修复环境(保留 .env 与数据库)"
|
||||
step "修复环境(保留 .env 与数据库) slot=${INSTANCE_SLOT}"
|
||||
run_pipeline "${REPO_ROOT}"
|
||||
}
|
||||
|
||||
handle_existing() {
|
||||
echo ""
|
||||
echo "检测到已部署: ${INSTALL_ROOT}"
|
||||
echo "检测到已部署: ${INSTALL_ROOT}(槽位 ${INSTANCE_SLOT})"
|
||||
echo " a) 取消"
|
||||
echo " b) 修复/重装环境(保留 .env 与 SQLite)"
|
||||
local choice=""
|
||||
@@ -59,6 +62,15 @@ handle_existing() {
|
||||
|
||||
main_install() {
|
||||
require_root
|
||||
# manage.sh 已 prompt;直接调用时按 INSTANCE_SLOT / INSTALL_ROOT 对齐
|
||||
if [[ "${INSTALL_ROOT}" == "/opt/eth_hedge_sim_2" ]]; then
|
||||
resolve_slot 2
|
||||
elif [[ "${INSTALL_ROOT}" == "/opt/eth_hedge_sim_3" ]]; then
|
||||
resolve_slot 3
|
||||
else
|
||||
resolve_slot "${INSTANCE_SLOT:-1}"
|
||||
fi
|
||||
|
||||
if repo_ready "${INSTALL_ROOT}"; then
|
||||
handle_existing
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user