I am looking for a way to suspend the laptop, not go to hibernate but power down once a certain amount of time has gone. This avoids swap partitions and secure boot problems, but still saves the battery when not in use.
I found the following possible solution, but since I am not too familiar with Linux I am wondering whether this would work: suspend-then-shutdown sleep option? / Newbie Corner / Arch Linux Forums
$ cat /etc/systemd/system/systemd-suspend.service
[Unit]
Description=Suspend; Shutdown if not used for a period of time
[Service]
Type=oneshot
ExecStart=/usr/local/bin/suspend-then-shutdown
$ cat /usr/local/bin/suspend-then-shutdown
#!/bin/sh
delay=$((2*3600))
start=$(date +%s)
rtcwake -s $delay -m mem
end=$(date +%s)
if [ $((end-start)) -ge $delay ]; then
systemd-run --on-active=5 systemctl poweroff
fi
Please note that I've used this on Debian 11, currently don't have Arch to test but I suppose that it should work with newer systemd as well.
Note that I've replaced (not overridden) the suspend target, not suspend-than-hibernate, which may seem more appropriate. But invoking systemctl suspend-than-hibernate is refused for me, because I use Secure Boot and lockdown mode doesn't allow hibernation.
UPDATE 2023-06-17: replaced shutdown -h now
by systemd-run [...] poweroff
- it seems like newer systemd doesn't allow entering shutdown when in midst of sleep target.
Last edited by MartinPulec (2023-06-17 16:46:46)