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: systemctl set-property sets a systemd resource limit on a running service

Systemd
~/tips/tip-systemd-set-property-memorymax

systemctl show nginx.service -p MemoryMax -p CPUQuotaPerSecUSec

Applies memory and CPU limits to a running service, temporarily or permanently, without editing files.

To rein in a leaky service quickly I set a limit at runtime and check it, before I write anything to a unit file.

sudo systemctl set-property --runtime nginx.service MemoryMax=500M CPUQuota=50%
systemctl show nginx.service -p MemoryMax -p CPUQuotaPerSecUSec

MemoryMax= is a hard cgroup limit. When the service exceeds it the kernel reclaims memory and may kill processes inside it. CPUQuota=50% caps the service at half of one core. --runtime keeps the change until reboot, and without it systemd writes a persistent drop-in under /etc/systemd/system.control. The limits need cgroup v2 on current Debian and Ubuntu releases.

Further reading: systemd.resource-control 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