Hi, I follow the following wiki page to setup a suspend sedation systemd
service.
https://wiki.debian.org/SystemdSuspendSedation
Code:
<http://forums.debian.net/viewtopic.php?f=5&t=129088#>#
/etc/systemd/system/suspend-sedation.service
[Unit]
Description=Hibernate after suspend
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1574125#p1574125
Documentation=https://wiki.archlinux.org/index.php/Power_management
Documentation=https://wiki.debian.org/SystemdSuspendSedation
Conflicts=hibernate.target hybrid-suspend.target
Before=suspend.target
StopWhenUnneeded=true

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="ALARM_SEC=300"
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"

ExecStart=/usr/sbin/rtcwake --seconds $ALARM_SEC --auto --mode no
ExecStop=/bin/sh -c '\
ALARM=$(cat $WAKEALARM); \
NOW=$(date +%%s); \
if [ -z "$ALARM" ] || [ "$NOW" -ge "$ALARM" ]; then \
  echo "suspend-sedation: Woke up - no alarm set. Hibernating..."; \
  systemctl hibernate; \
else \
  echo "suspend-sedation: Woke up before alarm - normal wakeup."; \
  /usr/sbin/rtcwake --auto --mode disable; \
fi \
'

[Install]
WantedBy=sleep.target
RequiredBy=suspend.target

The goal is to allow my laptop first suspend when I close lid and if I dose
not open lid for 5 min then it will hibernate.

This service works as expected when my AC adapter is connected. But when my
laptop works on battery, its behavior is very strange.

1. Suppose I disconnect my AC adapter and closed the lid then my laptop
will immediately suspend.
2. 5 minutes later, my laptop will beep means that it wakes up. The
expecting behavior then is that it hibernates. But nothing happens.
3. If don't open the lid then the laptop keeps in suspend status.
4. If I open the lid then it will first wake up from suspend status and
then go to hibernate at this time.

The following log of suspend-sedation.service explains the above behavior.
Code:
$ journalctl -u suspend-sedation
— Logs begin at Mon 2016-08-01 21:26:15 CST, end at Tue 2016-08-02 15:46:05
CST// logs when work on AC
Aug 02 15:10:43 x301 systemd[1]: Starting Hibernate after suspend...
Aug 02 15:10:43 x301 rtcwake[16160]: rtcwake: wakeup using /dev/rtc0 at Tue
Aug
Aug 02 15:10:43 x301 systemd[1]: Started Hibernate after suspend.
Aug 02 15:15:47 x301 sh[16240]: suspend-sedation: Woke up - no alarm set.
Hibern
Aug 02 15:15:46 x301 systemd[1]: suspend-sedation.service: Unit not needed
anymo
Aug 02 15:15:46 x301 systemd[1]: Stopping Hibernate after suspend...
Aug 02 15:15:47 x301 systemd[1]: Stopped Hibernate after suspend.// logs
when works on battary
Aug 02 15:18:49 x301 systemd[1]: Starting Hibernate after suspend...
Aug 02 15:18:49 x301 rtcwake[16628]: rtcwake: wakeup using /dev/rtc0 at Tue
Aug
Aug 02 15:18:49 x301 systemd[1]: Started Hibernate after suspend.
Aug 02 15:27:13 x301 sh[16658]: suspend-sedation: Woke up - no alarm set.
Hibern
Aug 02 15:27:10 x301 systemd[1]: suspend-sedation.service: Unit not needed
anymo
Aug 02 15:27:10 x301 systemd[1]: Stopping Hibernate after suspend...
Aug 02 15:27:13 x301 systemd[1]: Stopped Hibernate after suspend.

The systemd version of my system is 230.

Dose anyone has a clue?
Cheers,
Qiang

Reply via email to