Stop Losing Work Mid-Job: Practical systemd-inhibit on Linux
You start a multi-hour rsync , walk away, and the laptop suspends halfway through. Or someone hits reboot while apt full-upgrade is unpacking. Or a headless box with IdleAction=suspend parks itself mid-backup because every session looked idle. Those are not application bugs. They are missing inhibitor locks . systemd-logind owns a small, deliberate API for this: applications (and operators) can…
When performing long-running tasks on Linux, such as rsync or backups, it's common for the system to unexpectedly suspend, shut down, or enter idle mode, interrupting the job. This issue arises when no inhibitor locks are in place to prevent these types of interruptions. Inhibitor locks are a feature of systemd-logind that allow applications and operators to temporarily block or delay sleep, shutdown, idle action, and even the handling of power/lid keys.
The command-line front end for managing these locks is systemd-inhibit. The protocol for these locks is detailed in the upstream Inhibitor Locks page and the org.freedesktop.login1(5) documentation.
This guide is aimed at operators and provides step-by-step instructions on listing active locks, wrapping real jobs to prevent interruptions, putting inhibitors on oneshot services, tuning logind.conf delay budgets, and knowing when not to take a blocking lock. It is important to understand that inhibitor locks do not replace backups, fencing, or package-manager locks; they simply prevent logind-mediated interruptions and allow the job to complete uninterrupted.
The mental model for using inhibitor locks involves a single D-Bus call: Inhibit(what, who, why, mode) → file descriptor. After executing the command, the lock is automatically removed when the file descriptor is closed, ensuring no stale locks are left in the database.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.