You are not logged in.

#1 2021-01-25 12:58:15

justdanyul
Member
Registered: 2011-09-29
Posts: 137

Any way of cancelling sleep?

I short, I'm looking for a way to cancel a pending request to put the system into sleep. 

So, for example

1. systemctl suspend is called
2. I run a script in the sleep hook (as per the arch wiki)
3. depending on the outcome of the script in two, eighter allow the system to go to sleep, or cancels the sleep request

I've tried calling systemd-inhibit from a sleep hook, but I get the message

Failed to inhibit: The operation inhibition has been requested for is already running

which is pretty clear. So, it doesn't seem like inhibiting post-sleep request will work, so I'm wondering if there is any way to programmatically cancel a scheduled sleep request?

Offline

#2 2021-01-26 17:16:49

Ferdinand
Member
From: Norway
Registered: 2020-01-02
Posts: 338

Re: Any way of cancelling sleep?

Consider the systemd-suspend.service:

[Unit]
Description=Suspend
Documentation=man:systemd-suspend.service(8)
DefaultDependencies=no
Requires=sleep.target
After=sleep.target

[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/systemd-sleep suspend

I wonder if it might be a good approach to write a replacement unit file, and override the ExecStart with your script?
Edit: I should mention that this just fell out of my head - I haven't actually tried it tongue

Last edited by Ferdinand (2021-01-26 17:18:21)

Offline

#3 2021-01-26 18:49:09

progandy
Member
Registered: 2012-05-17
Posts: 5,317

Re: Any way of cancelling sleep?

I think a better solution may be to create a service that is required by the sleep target. Then a failure of that service should prevent the sleep.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

Board footer

Powered by FluxBB