diff --git a/Sleep-Hibernate/ges-alim-1.png b/Sleep-Hibernate/ges-alim-1.png new file mode 100644 index 0000000..1008ddf Binary files /dev/null and b/Sleep-Hibernate/ges-alim-1.png differ diff --git a/Sleep-Hibernate/ges-alim-2.png b/Sleep-Hibernate/ges-alim-2.png new file mode 100644 index 0000000..b1c4ff4 Binary files /dev/null and b/Sleep-Hibernate/ges-alim-2.png differ diff --git a/Sleep-Hibernate/ges-alim-3.png b/Sleep-Hibernate/ges-alim-3.png new file mode 100644 index 0000000..e1576e2 Binary files /dev/null and b/Sleep-Hibernate/ges-alim-3.png differ diff --git a/Sleep-Hibernate/ges-alim-4.png b/Sleep-Hibernate/ges-alim-4.png new file mode 100644 index 0000000..ce64f49 Binary files /dev/null and b/Sleep-Hibernate/ges-alim-4.png differ diff --git a/Sleep-Hibernate/sleep-hibernate.md b/Sleep-Hibernate/sleep-hibernate.md new file mode 100644 index 0000000..ac3158b --- /dev/null +++ b/Sleep-Hibernate/sleep-hibernate.md @@ -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)