From b9d47e0f05b881ed0b1e964730f1497c76399d91 Mon Sep 17 00:00:00 2001 From: yanyu Date: Wed, 8 Jul 2026 15:28:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20nvm=20node=20=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sandbox-worker/install.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sandbox-worker/install.sh b/sandbox-worker/install.sh index 277f55a..ef4a420 100644 --- a/sandbox-worker/install.sh +++ b/sandbox-worker/install.sh @@ -23,9 +23,14 @@ KEEP_BACKUPS=3 [[ "$(id -u)" == "0" ]] || { echo "❌ 请用 root / sudo 运行" >&2; exit 1; } [[ "$(uname -s)" == "Linux" ]] || { echo "❌ 仅支持 Linux" >&2; exit 1; } command -v curl >/dev/null || { echo "❌ 需要 curl" >&2; exit 1; } -command -v node >/dev/null || { echo "❌ 需要 Node.js ≥ 22" >&2; exit 1; } -NODE_MAJOR=$(node -e 'console.log(process.versions.node.split(".")[0])') -[[ "${NODE_MAJOR}" -ge 22 ]] || { echo "❌ Node ≥ 22(当前 $(node -v))" >&2; exit 1; } +# node 可能装在普通用户的 nvm 下(root PATH 看不见)—— 先 PATH 找,再借 SUDO_USER 的登录环境找 +NODE_BIN="$(command -v node || true)" +if [[ -z "${NODE_BIN}" && -n "${SUDO_USER:-}" ]]; then + NODE_BIN="$(su - "${SUDO_USER}" -c 'command -v node' 2>/dev/null || true)" +fi +[[ -n "${NODE_BIN}" ]] || { echo "❌ 需要 Node.js ≥ 22(root 与 ${SUDO_USER:-当前用户} 的 PATH 均未找到 node)" >&2; exit 1; } +NODE_MAJOR=$("${NODE_BIN}" -e 'console.log(process.versions.node.split(".")[0])') +[[ "${NODE_MAJOR}" -ge 22 ]] || { echo "❌ Node ≥ 22(当前 $("${NODE_BIN}" -v))" >&2; exit 1; } command -v docker >/dev/null || { echo "❌ 需要 Docker(worker 用它起沙箱容器)" >&2; exit 1; } if [[ "${1:-}" == "--uninstall" ]]; then @@ -91,7 +96,7 @@ Wants=network-online.target [Service] EnvironmentFile=${APP_DIR}/.env -ExecStart=$(command -v node) ${APP_DIR}/current/dist/server.js +ExecStart=${NODE_BIN} ${APP_DIR}/current/dist/server.js WorkingDirectory=${APP_DIR}/current Restart=always RestartSec=3