summarylogtreecommitdiffstats
path: root/suspend2hibernation.service
diff options
context:
space:
mode:
authorKopfKrieg2017-06-30 22:06:39 +0200
committerKopfKrieg2017-06-30 22:06:39 +0200
commit40c60040e3f7e3be7718461550ab752adb7ea143 (patch)
treea3728523ed448b8383ef50be39448f23bafb5711 /suspend2hibernation.service
downloadaur-40c60040e3f7e3be7718461550ab752adb7ea143.tar.gz
Initial v0.1 of the suspend2hibernation service
Diffstat (limited to 'suspend2hibernation.service')
-rw-r--r--suspend2hibernation.service28
1 files changed, 28 insertions, 0 deletions
diff --git a/suspend2hibernation.service b/suspend2hibernation.service
new file mode 100644
index 000000000000..ba9ed16377ec
--- /dev/null
+++ b/suspend2hibernation.service
@@ -0,0 +1,28 @@
+[Unit]
+Description=Suspend to hibernation / delayed hibernation
+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-sleep.target
+StopWhenUnneeded=true
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
+Environment="SLEEPLENGTH=+20minute"
+ExecStart=-/usr/bin/sh -c 'echo -n "alarm set for "; date +%%s -d$SLEEPLENGTH | tee $WAKEALARM'
+ExecStop=-/usr/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