Files
memind_adm/scripts/remote_restart.sh
T
2026-06-20 16:52:13 +08:00

61 lines
2.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 在 100 服务器上重启 memind_admvite preview + API 反代)
set -euo pipefail
ROOT="${ADM_ROOT:-/Users/john/Project/memind_adm}"
PORT="${ADM_PORT:-5174}"
NODE_PATH="${LAN_NODE_PATH:-/opt/homebrew/opt/node@24/bin:/opt/homebrew/opt/node@22/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin}"
API_PORT="${ADM_API_PORT:-8085}"
LOG="${ROOT}/adm-preview.log"
API_LOG="${ROOT}/adm-api.log"
PID_FILE="${ROOT}/.adm-preview.pid"
API_PID_FILE="${ROOT}/.adm-api.pid"
export PATH="${NODE_PATH}:${PATH}"
command -v node >/dev/null 2>&1 || { echo "❌ 未找到 node" >&2; exit 1; }
cd "${ROOT}"
if [[ ! -d dist ]]; then
echo "${ROOT}/dist 不存在,请先构建或 rsync dist" >&2
exit 1
fi
if [[ ! -d node_modules ]]; then
echo "==> 安装依赖..."
npm install
fi
echo "==> 停止旧进程 (port ${PORT}, ${API_PORT})..."
lsof -ti "TCP:${PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill 2>/dev/null || true
lsof -ti "TCP:${API_PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill 2>/dev/null || true
sleep 1
lsof -ti "TCP:${PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill -9 2>/dev/null || true
lsof -ti "TCP:${API_PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill -9 2>/dev/null || true
echo "==> 启动 Admin API @ 127.0.0.1:${API_PORT}..."
nohup node server/index.mjs >>"${API_LOG}" 2>&1 &
echo $! >"${API_PID_FILE}"
sleep 2
if ! curl -sf "http://127.0.0.1:${API_PORT}/health" >/dev/null; then
echo "❌ Admin API 启动失败,最近日志:" >&2
tail -n 40 "${API_LOG}" >&2 || true
exit 1
fi
echo "==> 启动 vite preview @ 127.0.0.1:${PORT}..."
nohup npm run dev:preview -- --host 127.0.0.1 --port "${PORT}" >>"${LOG}" 2>&1 &
echo $! >"${PID_FILE}"
sleep 2
if curl -sf "http://127.0.0.1:${PORT}/" >/dev/null; then
echo "✅ memind_adm 已就绪: http://127.0.0.1:${PORT}/"
curl -sf "http://127.0.0.1:${PORT}/" >/dev/null && echo " 首页 OK"
echo " 登录请使用数据库中已初始化的 admin 账号"
else
echo "❌ 启动失败,最近日志:" >&2
tail -n 40 "${LOG}" >&2 || true
exit 1
fi