基础设施 3.0 · 值得看 2026-10-24 · 文章

Interesting systemd features you may not know about

Martin Alderson 把 systemd 重新介绍为跑 agent 生成代码的趁手工具:systemd-run --scope 配 MemoryMax/CPUQuota 给 Claude Code 限 4GB 内存 2 核(与 Docker 同为 cgroup 机制);RuntimeMaxSec 给自治任务设 30 分钟上限,OpenCode 须加 --standalone 否则后台 server 绕过时限;systemd-inhibit 防合盖睡眠;timer 的 Persistent 属性补上 cron 断电漏跑文末提醒 ProtectHome 沙箱虽适合 agent 但 footgun 多,留作下篇

打开原文回到归档

Interesting systemd features you may not know about

中文导读

Martin Alderson 对 systemd 的自我定位是『一直觉得它只是个启动系统、跑后台服务的无聊管道』,但它的资源限制特性恰好适合跑 agent 写的一次性代码:systemd-run --user --scope 加 MemoryMax=4G、CPUQuota=200% 即可给 Claude Code 限内存限核(底层与 Docker 同为 cgroup,systemd-cgtop 能按组看内存与 CPU);RuntimeMaxSec=30m 可给 OpenCode 的自治调查任务设 30 分钟上限——注意必须加 --standalone,否则默认后台 server 会绕过时限;systemd-inhibit --what=sleep:idle:handle-lid-switch 防合盖睡眠,与时限叠加防电量耗尽;timer 的 Persistent 属性让错过的任务在恢复在线后补跑,这是 cron 做不到的。文末预告:ProtectHome、ReadWritePaths 等沙箱特性看起来是 agent 的完美搭配,但 footgun 太多,留作后续文章。

为什么值得关注

agent 运维的最小可行安全绳:资源上限、时限、防睡眠三件套可直接照抄,属于拿来就能用的 harness 侧工具文。

关键信息

English Summary

Martin Alderson frames mundane systemd features as exactly the right tooling for running throwaway agent-written code: systemd-run --user --scope with MemoryMax=4G and CPUQuota=200% caps a Claude Code session using the same cgroup limits Docker uses (visible per-cgroup via systemd-cgtop); RuntimeMaxSec time-boxes an autonomous OpenCode run to 30 minutes, with the caveat that --standalone is required or a background server bypasses the limit; systemd-inhibit keeps laptops from sleeping mid-run and composes with runtime caps; timer units' Persistent option reruns missed jobs after downtime, which plain cron lacks. He notes ProtectHome/ReadWritePaths sandboxing looks ideal for agents but is full of footguns, deferred to a follow-up post.

原文摘录 (Excerpts)

systemd actually has tonnes of interesting features, that I think are even more useful for running throwaway agent-written code.
systemd-run --user --scope -p MemoryMax=4G -p CPUQuota=200% claude
the --standalone arg is required, because OpenCode by default will run its work on a background server which you may already have running, which will bypass the time limit.

Obsidian Notes

  • 从 AK-RSS-Digest 89源精选 2026-10-26 source 笔记全文提取(该笔记为 martinalderson.com 原文全文抓取,抓取时间 2026-10-26 Asia/Shanghai);导读与判断仅引用笔记内已核实内容。