fix(install): pin node absolute path in MEMORY_TENCENTDB_GATEWAY_CMD#54
Closed
YOMXXX wants to merge 1 commit into
Closed
fix(install): pin node absolute path in MEMORY_TENCENTDB_GATEWAY_CMD#54YOMXXX wants to merge 1 commit into
YOMXXX wants to merge 1 commit into
Conversation
When Hermes (or a standalone memory-tencentdb-gateway service) runs under systemd, the systemd environment's PATH is the minimal default (``/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin``) and does NOT inherit the user shell's nvm/asdf-augmented PATH. nvm installs node under ``~/.nvm/versions/node/v*/bin/`` and systemd cannot find it. Reported in Tencent#19 by @cuiweiyou: the install script's generated launch command used a bare ``npx tsx ...``. In an interactive shell (with nvm loaded via ``~/.bashrc``) this ran fine, but under systemd the fork-exec failed with ``/usr/bin/env: 'node': No such file or directory``, and the Gateway never came up. Hermes' watchdog kept logging "Gateway unreachable; attempting to resurrect." Fix: resolve ``node`` to its absolute path at install time via ``command -v node``, and use Node's native ``--import tsx/esm`` loader instead of ``npx`` so the final command has no runtime PATH dependency. Before: sh -c 'cd <plugin-dir> && exec npx tsx src/gateway/server.ts' After (NODE_BIN resolved at install time, e.g. /root/.nvm/versions/node/v25.8.2/bin/node): sh -c 'cd <plugin-dir> && exec "<NODE_BIN>" --import tsx/esm src/gateway/server.ts' A guard fails the install with a clear error message if ``node`` is not on PATH at install time, with hints for nvm/asdf users to source their loader script first. ``--import tsx/esm`` is stable in Node ≥ 20.6 (and the script already requires Node ≥ 22, see header comment), so this introduces no new runtime requirement. Closes Tencent#19. Signed-off-by: 李冠辰 <liguanchen@xiaomi.com>
Collaborator
|
Hi @YOMXXX, We've received your PR regarding the node path resolution in systemd environments. Thanks for the contribution! We'll review and follow up. |
5 tasks
Collaborator
|
内部已修改,随下个版本发出 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary | 摘要
修复 #19:install 脚本生成的 `MEMORY_TENCENTDB_GATEWAY_CMD` 用裸 `npx`,systemd 环境下 PATH 不含 nvm/asdf 装的 node → daemon spawn 失败、Hermes 反复日志 "Gateway unreachable"。改为 install 时 resolve node 绝对路径,并用 `node --import tsx/esm` 替代 `npx tsx`。
Fix #19: `MEMORY_TENCENTDB_GATEWAY_CMD` used bare `npx` which fails under systemd (nvm/asdf node not in systemd's minimal PATH). Now resolves node's absolute path at install time and uses Node-native `--import tsx/esm` to remove the runtime PATH dependency.
Root cause
`scripts/install_hermes_memory_tencentdb.sh:229` (before):
```bash
GATEWAY_CMD="sh -c 'cd $TDAI_INSTALL_DIR && exec npx tsx src/gateway/server.ts'"
```
/.bashrc` 加载 nvm → PATH 含 `/.nvm/versions/node/v*/bin/` → `npx` 找到 → OK```text
/usr/bin/env: 'node': No such file or directory
```
issue 报告者手动 workaround:systemd unit 显式写绝对 node 路径 + `Environment=PATH=...` 后 Gateway 正常启动。
Fix
```bash
NODE_BIN="$(command -v node || true)"
if [ -z "$NODE_BIN" ]; then
echo "[ERROR] 'node' not found in PATH; cannot generate Gateway start command." >&2
echo "[ERROR] If you installed Node via nvm/asdf, source the loader script for the install user before re-running:" >&2
echo "[ERROR] source ~/.bashrc # or 'nvm use '" >&2
exit 1
fi
echo "[memory-tencentdb] Resolved node: $NODE_BIN"
GATEWAY_CMD="sh -c 'cd $TDAI_INSTALL_DIR && exec \"$NODE_BIN\" --import tsx/esm src/gateway/server.ts'"
```
两点变化:
Install 时 `node` 不在 PATH 直接 fail-fast + 给出 nvm/asdf 用户的 hint,比生成一个不能跑的 `GATEWAY_CMD` 再等 runtime 报错好得多。
Compatibility | 兼容性
Manual test plan
```bash
Before fix (重现 issue):
1. nvm install node 22 + hermes 装好
2. 跑 install_hermes_memory_tencentdb.sh
3. cat /etc/profile.d/memory-tencentdb-env.sh → 看到裸 npx
4. 用 systemd unit 启动 → 日志 'node: No such file or directory'
After fix:
1. 同上 1-2 步
3. cat /etc/profile.d/memory-tencentdb-env.sh → 看到绝对 node 路径
export MEMORY_TENCENTDB_GATEWAY_CMD="sh -c 'cd ... && exec \"/root/.nvm/.../node\" --import tsx/esm src/gateway/server.ts'"
4. 用 systemd unit 启动 → curl http://127.0.0.1:8420/health 返回 200
```
Edge cases handled
Out of scope
DCO
Commit 带 `Signed-off-by: 李冠辰 liguanchen@xiaomi.com`。
Closes #19.