fix(system): 编译产物读 /proc、/sys 走 cat 兜底,运行状态资源监控与沙箱内存看门狗恢复

Deno 2 不带 --allow-all 时读 /proc、/sys 一律 NotCapable,部署环境资源监控一直无数据。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-06 23:40:41 +08:00
1 parent 708e99746c
commit 9268a4d920
9 files changed
+84 -19

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
// 读 /proc 与 /sys 的伪文件。
// Deno 2 把这两处当特权路径:不带 --allow-all 时 Deno.readTextFile 一律 NotCapable(--allow-read 及按路径授权都不行)。
// 开发 / 测试用 -A 能直接读;编译产物按最小权限运行,只能借 `cat` 子进程读(编译与 start 任务的 --allow-run 已含 cat)。
// 第一次遇到 NotCapable 后记住,后续直接走 cat。
let viaCat = false;
async function catText(path: string): Promise<string | null> {
try {
const o = await new Deno.Command("cat", { args: [path], stdout: "piped", stderr: "null" }).output();
return o.success ? new TextDecoder().decode(o.stdout) : null;
} catch {
return null;
}
}
/** 读不到(不存在、无权限、cat 不可用)返回 null */
export async function readProcText(path: string): Promise<string | null> {
if (viaCat) return await catText(path);
try {
return await Deno.readTextFile(path);
} catch (e) {
if (e instanceof Deno.errors.NotCapable) {
viaCat = true;
return await catText(path);
}
return null;
}
}