diff --git a/README.md b/README.md index b9a40de..b8a6361 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,8 @@ Python 后端依赖由部署脚本安装到项目根目录 `.venv`。 前端依赖由部署脚本在 `frontend/app` 下执行 `npm ci` 安装,并执行 `npm run build`。 +部署脚本会把当前 shell 中可用的 `npm` 路径写入 `.env.deploy`,避免用户级 systemd 服务启动时读取不到 zsh/nvm 环境。 + 默认部署使用用户级 systemd,不需要 sudo。若机器要求服务在用户退出 SSH 后仍保持运行,可由管理员额外执行: ```bash diff --git a/scripts/deploy-ubuntu.sh b/scripts/deploy-ubuntu.sh index 3b9c9b6..0c6246b 100755 --- a/scripts/deploy-ubuntu.sh +++ b/scripts/deploy-ubuntu.sh @@ -233,6 +233,28 @@ build_frontend() { npm run build } +remember_node_runtime() { + local npm_bin node_bin node_bin_dir tmp_file + npm_bin="$(command -v npm || true)" + node_bin="$(command -v node || true)" + [[ -n "${npm_bin}" ]] || fail "无法定位 npm。" + node_bin_dir="$(dirname "${npm_bin}")" + tmp_file="$(mktemp)" + grep -v -E '^(export )?CLAW_(NPM_BIN|NODE_BIN|NODE_BIN_DIR)=' "${ENV_FILE}" >"${tmp_file}" || true + cat >>"${tmp_file}" <&2 + echo "Run deploy again from a shell where npm is available: bash scripts/deploy-ubuntu.sh" >&2 + exit 1 +fi export CLAW_API_URL="${CLAW_API_URL:-http://${BACKEND_HOST}:${BACKEND_PORT}}" cd "${ROOT_DIR}/frontend/app" -exec npm run start -- --hostname "${FRONTEND_HOST}" --port "${FRONTEND_PORT}" +exec "${NPM_BIN}" run start -- --hostname "${FRONTEND_HOST}" --port "${FRONTEND_PORT}"