Command line "Manually block" power saving

1.) Is there any command line to enable/disable the “Manually block” feature? I want to use it in a script.


2.) Is there any command line to temporarily disable suspend/hibernate only?

Thank you.

Yes, systemd-inhibit

2 Likes

Thank you for the reply. I thought qdbus or dbus-send was used for this, but I haven’t found any solution that works.

Systemd-inhibit works. In my case I used this for QEMU:

systemd-inhibit --what=sleep:shutdown --who="QEMU" --why="Because PCI passthrough" qemu-system-x86_64 $OPTS

1 Like

Theoretically it should also work via D-Bus but just not with the simple command line tools.

The inhibition requires that the requester stays connected to the bus, i.e. keeps “running”.
This is to protect against the issue of a process crashing while it holds an inhibit lock.

Tools like qdbus exit after the call so their lock is released essentially right after it has been created.
It could be done with a more direct access to D-Bus, e.g. Python and its D-Bus API.

However, systemd-inhibit was specifically created for this task so it is the most convenient solution :slight_smile:

2 Likes