Size process arguments from the number of CPUs gopherd detects, so the same config adapts to whatever host or container it runs in.
# CPU-aware templates: size args from detected CPUs (system + cgroup).
processes:
- name: app
command: /usr/local/bin/app
args: ["--workers", "{{cpu 50%}}", "--max", "{{cpu}}"]
on-failure: shutdown{{cpu}}— bare form expands to the detected CPU count.{{cpu 50%}}— percentage form expands to that fraction of the count (rounded).- Detection prefers cgroup limits over the system count: cgroup v2
cpu.maxCFS quota, v1cpu.cfs_quota_us/cpu.cfs_period_us, andcpusetare honored, falling back to the host CPU count. - CPU templates expand at service start (in
argsandenvironment), not at config load, so the value reflects the runtime environment.
- On a 4-CPU host with no cgroup limit,
appstarts with--workers 2 --max 4. - Under a cgroup CFS quota of 2 CPUs, it starts with
--workers 1 --max 2. - The config is portable: no hardcoded core counts.
ValidateParse level — behavior is environment-dependent (cgroup limits / remote syslog / file rotation thresholds), so the test asserts the config loads and validates.
go test ./documentation/cpu-template/ -v