Persist npm path for user services
This commit is contained in:
@@ -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}" <<EOF
|
||||
|
||||
# systemd 用户服务不会读取交互式 shell 配置,这里记录部署时可用的 Node.js/npm 路径。
|
||||
export CLAW_NPM_BIN=$(printf "%q" "${npm_bin}")
|
||||
export CLAW_NODE_BIN=$(printf "%q" "${node_bin}")
|
||||
export CLAW_NODE_BIN_DIR=$(printf "%q" "${node_bin_dir}")
|
||||
EOF
|
||||
install -m 0600 "${tmp_file}" "${ENV_FILE}"
|
||||
rm -f "${tmp_file}"
|
||||
log "记录 Node.js 运行路径"
|
||||
echo "npm=${npm_bin}"
|
||||
echo "node=${node_bin:-未检测到}"
|
||||
}
|
||||
|
||||
install_systemd_service() {
|
||||
local service_name="$1"
|
||||
local template_path="$2"
|
||||
@@ -290,6 +312,7 @@ main() {
|
||||
ensure_env_file
|
||||
ensure_python
|
||||
build_frontend
|
||||
remember_node_runtime
|
||||
install_services
|
||||
restart_services
|
||||
health_check
|
||||
|
||||
Reference in New Issue
Block a user