Interesting systemd features you may not know about
- ID: 4a16545b
- 原文链接: https://martinalderson.com/posts/interesting-systemd-features/
- 作者: Martin Alderson
- 日期: 2026-10-24
- 分类: infra
- 来源类型: article
- 标签: systemd, agent-ops, resource-limits, sandboxing, linux
- 质量评分: 3/5
- 抓取时间: 2026-10-26T15:42:56Z
中文导读
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 侧工具文。
关键信息
- 文章标题: Interesting systemd features you may not know about
- 作者: Martin Alderson
- 原文链接: https://martinalderson.com/posts/interesting-systemd-features/
- 发布时间: 2026-10-24
- 关联标签: systemd, agent-ops, resource-limits, sandboxing, linux
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);导读与判断仅引用笔记内已核实内容。