# /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
$ 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?