add sleep hibernate

Michel Le Cocq 2022-07-31 11:40:08 +02:00
parent 68ea3be20a
commit 0e1f1cd2c7
5 changed files with 178 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

@ -0,0 +1,178 @@
---
format: markdown
title: suspend-to-hibernate service
...
# explication
Si la machine est en veille 5min alors elle passe en hibernation.
On place une *heure de reveil* (+4min par rapport à l'heure actuelle) dans *WAKEALARM* /sys/class/rtc/rtc0/wakealarm et on dit à la machine de se réveiller dans 5min via *rtcwake* :
~~~
SLEEPLENGTH=+4min
alarm set for " $(/bin/date -d "$SLEEPLENGTH") > /sys/class/rtc/rtc0/wakealarm
rtcwake --seconds 600 --auto --mode no'
~~~
Au réveil on vérifie la valeur de l'alarme pour passer en mode hibernation ou rendre la machine active :
~~~
WAKEALARM=/sys/class/rtc/rtc0/wakealarm
ALARM=$(cat $WAKEALARM)
NOW=$(/bin/date +%s)
if [ -z "$ALARM" ] || [ "$NOW" -ge "$ALARM" ]; then
echo "hibernate triggered"
systemctl hibernate || systemctl suspend
else
echo "normal wakeup, clearing RTC alarm."
rtcwake --auto --mode disable
fi
~~~
**man rtcwake** (extrait) :
~~~
rtcwake - enter a system sleep state until specified wakeup time
-a, --auto
Read the clock mode (whether the hardware clock is set to UTC
or local time) from the adjtime file, where hwclock(8)
stores that information. This is the default.
-m, --mode mode
no Don't suspend, only set the RTC wakeup time.
~~~
# script complet
## systemd suspend.target
ajouter : Requires=suspend-to-hibernate.service dans /lib/systemd/system/suspend.target :
~~~{.bash}
$ cat /lib/systemd/system/suspend.target
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Suspend
Documentation=man:systemd.special(7)
DefaultDependencies=no
BindsTo=systemd-suspend.service
After=systemd-suspend.service
Requires=suspend-to-hibernate.service
~~~
## suspend-to-hibernate.service
edit : /lib/systemd/system/suspend-to-hibernate.service
~~~{.bash}
Description=Delayed hibernation suspend -> hibernate
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279
Documentation=https://wiki.archlinux.org/index.php/Power_management
Before=suspend.target
Conflicts=hibernate.target hybrid-suspend.target
StopWhenUnneeded=true
[Service]
Type=oneshot
RemainAfterExit=yes
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
Environment="SLEEPLENGTH=+39min"
ExecStart=/bin/bash -c '\
/bin/echo -n "alarm set for " $(/bin/date -d "$SLEEPLENGTH"); \
/bin/echo $(/bin/date +%s -d "$SLEEPLENGTH") > $WAKEALARM; \
/bin/echo;\
/usr/sbin/rtcwake --seconds 2400 --auto --mode no'
ExecStop=/bin/sh -c '\
NOW=$(date '+%s'); \
ALARM=$(cat $WAKEALARM); \
/bin/echo "ALARM wake for hibernate :"$ALARM; \
/bin/echo "NOW :"$NOW; \
if [ -z "$ALARM" ] || [ "$NOW" -ge "$ALARM" ]; then \
/bin/echo "hibernate triggered"; \
/bin/systemctl hibernate || /bin/systemctl suspend; \
else \
/bin/echo "normal wakeup, clearing RTC alarm."; \
/usr/sbin/rtcwake --auto --mode disable; \
fi;'
[Install]
WantedBy=sleep.target
~~~
~~~{.bash}
root@houyo:/lib/systemd/system# systemctl start suspend-to-hibernate
root@houyo:/lib/systemd/system# systemctl enable suspend-to-hibernate
Created symlink from /etc/systemd/system/sleep.target.wants/suspend-to-hibernate.service to /lib/systemd/system/suspend-to-hibernate.service.
root@houyo:/lib/systemd/system#
~~~
# Gestionnaire Alimention Xfce
![](/Sleep-Hibernate/ges-alim-1.png)
![](/Sleep-Hibernate/ges-alim-2.png)
![](/Sleep-Hibernate/ges-alim-3.png)
![](/Sleep-Hibernate/ges-alim-4.png)
# ce qui dois arriver
## inactivitée sur batterie
* 1m30s : reduire la luminosité à 5%
* 2m : écran vide
* 15m : mettre en veille sur Ram le système
* 40m : passer de veille sur Ram à veille sur disque
## inactivitée sur secteur
Quand branché sur le secteur aucun paramètre de mise en veille n'est activé.
* 1m30s : reduire la luminosité à 5%
* 2m : écran vide
# trouble
## ask for passwd
Automatic suspend from the xfce power manager does not work, as a window opens and asks for my password. Well, if it wants to suspend the system after a given timeout, I cannot enter my password as I'm not in front of my system then. Once I'm able to enter my password it is too late to run the suspend action.
message in the upper corner saying :
~~~
Power Manager: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Method call timed out.
~~~
Put **light-locker setting** *Auto Lock Session* to **When the screensaver is deactivated** to solves the problem.
see :
* [Ubuntu Bug : 1605189 Authentication is required for suspending the system](https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1605189)
* [Xubuntu Bug : Failing to sleep after inactivity - power manager error ?](https://bugs.launchpad.net/ubuntu/+source/xfce4-power-manager/+bug/1441460)
## There's already a shutdown or sleep operation in progress
~~~
Failed to hibernate system via logind: There's already a shutdown or sleep operation in progress
Failed to suspend system via logind: There's already a shutdown or sleep operation in progress
~~~
missing in : /lib/systemd/system/suspend.target
~~~
Requires=suspend-to-hibernate.service
~~~
# source
* [askubuntu how-to-go-automatically-from-suspend-into-hibernate](http://askubuntu.com/questions/12383/how-to-go-automatically-from-suspend-into-hibernate/662701#662701?newreg=9ae06dac594046939234f1aa433c9a16)
* [ArchLinux suspend broken since systemd update](https://bbs.archlinux.org/viewtopic.php?id=204346)