brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemd-run --user --scope applies resource limits to any command

Systemd
~/tips/tip-systemd-run-scope-limits

systemd-run --user --scope -p MemoryMax=2G -p CPUQuota=200% make -j8

Runs a command in a temporary cgroup with memory and CPU limits, no unit file needed.

A heavy build can freeze the desktop, so I start it inside a limited cgroup.

systemd-run --user --scope -p MemoryMax=2G -p CPUQuota=200% make -j8

systemd-run puts the command in a transient scope unit with the given properties, and the limits disappear when the command exits. CPUQuota=200% allows two cores in total. --user uses your own systemd instance, so no root is needed. The limits only work when the system uses cgroup v2 and the matching controllers are delegated to your user manager. If a controller is missing, the limit has no effect, so test with a command that really uses the memory or CPU before you rely on it.

Further reading: systemd-run manual page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link