feat: scaffold gold_monitor web hub, API, PM2 deploy and docs

This commit is contained in:
dekun
2026-10-17 17:43:17 +08:00
commit fb35968a1f
35 changed files with 2080 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# shellcheck shell=bash
detect_server_ip() {
local ip
ip="$(hostname -I 2>/dev/null | awk '{print $1}')"
if [[ -z "${ip}" ]]; then
ip="$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="src"){print $(i+1); exit}}')"
fi
echo "${ip:-127.0.0.1}"
}
need_root() {
if [[ "$(id -u)" -ne 0 ]]; then
echo "错误: 请使用 root 执行" >&2
exit 1
fi
}
ensure_node_pm2() {
if ! command -v node >/dev/null 2>&1; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
fi
if ! command -v pm2 >/dev/null 2>&1; then
npm install -g pm2
fi
}
verify_http() {
local url="$1"
curl -fsS --max-time 5 "${url}" >/dev/null 2>&1
}
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# shellcheck shell=bash
set -euo pipefail
# shellcheck source=common.sh
source "${LIB_DIR}/common.sh"
need_root
echo "[1/4] 安装系统依赖 / venv ..."
bash "${REPO_ROOT}/deploy/setup_env.sh"
echo "[2/4] 安装 Node / PM2 ..."
ensure_node_pm2
echo "[3/4] 启动 PM2 ..."
cd "${REPO_ROOT}"
pm2 delete gold_monitor >/dev/null 2>&1 || true
pm2 start "${REPO_ROOT}/deploy/ecosystem.config.cjs"
pm2 save
pm2 startup systemd -u root --hp /root >/dev/null 2>&1 || true
echo "[4/4] 验收 ..."
sleep 2
IP="$(detect_server_ip)"
if verify_http "http://127.0.0.1:5800/health"; then
echo "✓ 健康检查通过"
else
echo "✗ 健康检查失败,请执行: pm2 logs gold_monitor" >&2
exit 1
fi
echo ""
echo "部署完成"
echo " 地址: http://${IP}:5800"
echo " 登录: admin / admin123 (请立即修改 .env 中 ADMIN_PASSWORD)"
echo " 管理: bash ${REPO_ROOT}/deploy/manage.sh"
echo ""
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# shellcheck shell=bash
set -euo pipefail
# shellcheck source=common.sh
source "${LIB_DIR}/common.sh"
need_root
TS="$(date +%Y%m%d_%H%M%S)"
BACKUP="/opt/gold_monitor_backup_${TS}"
mkdir -p "${BACKUP}"
[[ -f "${REPO_ROOT}/.env" ]] && cp "${REPO_ROOT}/.env" "${BACKUP}/"
[[ -d "${REPO_ROOT}/data" ]] && cp -a "${REPO_ROOT}/data" "${BACKUP}/" || true
pm2 delete gold_monitor >/dev/null 2>&1 || true
pm2 save >/dev/null 2>&1 || true
echo "已备份到 ${BACKUP}"
read -r -p "是否删除目录 ${REPO_ROOT}? [y/N] " ans
if [[ "${ans}" == "y" || "${ans}" == "Y" ]]; then
rm -rf "${REPO_ROOT}"
echo "已删除 ${REPO_ROOT}"
else
echo "保留目录,仅停止 PM2 进程"
fi
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# shellcheck shell=bash
set -euo pipefail
# shellcheck source=common.sh
source "${LIB_DIR}/common.sh"
need_root
echo "更新子菜单"
echo " 1) 快速更新 (git pull + pm2 restart)"
echo " 2) 依赖更新 (pull + pip + restart)"
echo " 0) 返回"
read -r -p "选择: " choice
case "${choice}" in
1)
git -C "${REPO_ROOT}" pull --ff-only
pm2 restart gold_monitor
;;
2)
git -C "${REPO_ROOT}" pull --ff-only
bash "${REPO_ROOT}/deploy/setup_env.sh"
pm2 restart gold_monitor
;;
*)
echo "取消"
;;
esac