From 46f37bf648c07bce17aad2f598696add5f83bd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Wed, 4 Oct 2017 12:26:16 +0200 Subject: [PATCH] Add suspend-to-hibernate --- suspend-to-hibernate/PKGBUILD | 13 +++++++++ .../suspend-to-hibernate.service | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 suspend-to-hibernate/PKGBUILD create mode 100644 suspend-to-hibernate/suspend-to-hibernate.service diff --git a/suspend-to-hibernate/PKGBUILD b/suspend-to-hibernate/PKGBUILD new file mode 100644 index 0000000..607cde4 --- /dev/null +++ b/suspend-to-hibernate/PKGBUILD @@ -0,0 +1,13 @@ +# Maintainer: Manuel Vögele +pkgname=suspend-to-hibernate +pkgver=1 +pkgrel=1 + +arch=('any') +source=('suspend-to-hibernate.service') +md5sums=('SKIP') + +package() { + mkdir -p "${pkgdir}/etc/systemd/system/" + cp "${srcdir}/suspend-to-hibernate.service" "${pkgdir}/etc/systemd/system/suspend-to-hibernate.service" +} diff --git a/suspend-to-hibernate/suspend-to-hibernate.service b/suspend-to-hibernate/suspend-to-hibernate.service new file mode 100644 index 0000000..55a2fe5 --- /dev/null +++ b/suspend-to-hibernate/suspend-to-hibernate.service @@ -0,0 +1,28 @@ +[Unit] +Description=Delayed hibernation trigger +Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279 +Documentation=https://wiki.archlinux.org/index.php/Power_management +Conflicts=hibernate.target hybrid-sleep.target +Before=sleep.target +StopWhenUnneeded=true + +[Service] +Type=oneshot +RemainAfterExit=yes +Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm" +Environment="SLEEPLENGTH=+30minute" +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