~tim/ubuntu_on_surface_go

ubuntu_on_surface_go/suspend-to-hibernate.service -rw-r--r-- 627 bytes
f77d614fTim Morgan Simplify suspend/hibernate notes 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[Unit]
Description=delayed hibernation trigger
Before=suspend.target
StopWhenUnneeded=true
Conflicts=hibernate.target hybrid-suspend.target

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
ExecStart=-/bin/sh -c 'echo -n "alarm set for "; date +%%s -d+10minute | tee $WAKEALARM'
ExecStop=-/bin/sh -c '\
  alarm=$(cat $WAKEALARM); \
  now=$(date +%%s); \
  if [ -z "$alarm" ] || [ "$now" -ge "$alarm" ]; then \
     echo "hibernate triggered"; \
     systemctl hibernate; \
  else \
     echo "normal wakeup"; \
  fi; \
  echo 0 > $WAKEALARM; \
'

[Install]
WantedBy=sleep.target