Who is inhibiting my sleep?

Modern Linux desktop survival tips

George Shuklin
OpsOps
3 min readNov 3, 2019

--

You press a sleep button, and instead of getting into sleep, your PC is unhappy:

org.freedesktop.login1.suspend-ignore-inhibit request

While you can feel a bit frustrated, this thing is not an evil user-bender (like a Gnome3 touch-forceful interface). This is a request from one of applications to not to suspend. This is a beautiful generic mechanism, which brings a very little policy and a lot of mechanism (which is great). Moreover, it become the universal coordination point. Older systems have sets of mutual hooks and scripts (thousands bashes to you!), which was error-prone (thousands bashes, yes), hard to understand, to debug and to maintain.

Now they are unified in a single reasonable way. Systemd haters may want to stop reading this.

Inhibitors

Systemd brought to us idea of ‘inhibitors’, a universal way to influence how some system-wide events are handled. This is a list of operations which are currently covered (fall of 2019) by inhibitors:

  • shutdown
  • sleep
  • idle (the way to detect ‘idle’ for the needs of suspend/shutdown)
  • handle-power-key
  • handle-suspend-key
  • handle-hibernate-key
  • handle-lid-switch

Except for ‘shutdown’, most of those are not server-related, and, traditionally, was handled really uneven and messy.

Currently there are two ways to inhibit operation: delay or block. Block is prohibit operation (f.e. some program is asking not to suspend), delay is like a block, but with timeout. If delay inhibitor wasn’t released in time, it is ignored. Block inhibitor is like ‘delay with infinite time’.

Currently domain freedesktop.org is in expired mode so I can’t check documentation on who have rights to do this, but the thing is that you can use it for many useful things (like locking a laptop sleeping while your program is running).

There is an utility systemd-inhibit, which allows to set lock (f.e. systemd-inhibit ansible-play play.yaml will prohibit sleep while ansible-playbook is running).

Moreover, there is a --list option, which allows to see existing inhibitors:

example of systemd-inhibit --list on home machine

Just look at this beauty:

Cinnamon asked not to handle lid-switch because I have an external monitor (and normal lid-close would cause my laptop to go to sleep). Funny enough, this is PC with no lid, but cinnamon uses the same behavior in all cases when there is an external monitor.

sleep is delayed to help cinnamon to lock screen. This is really good one, as it allows to block screen before putting computer to sleep. It’s well-known bug for many screensavers to lock screen after computer woke up, therefore revealing content of the screen for an instant after wake. Not anymore.

And, finally, we can see the reason for this article: Disk Manager inhibit shutdown/sleep/idle because of ‘mdraid-check-job’. Yes, I have a software raid on my PC, and it doing it’s monthly job of checking raid consistency.

What about suspend-ignore-inhibit? As you can understand, it’s a permission to ignore those inhibits. It’s explicitly asked from used, because I pressed a sleep button, but linux-raid is busy with my disks.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.