Skip to content

Instantly share code, notes, and snippets.

@orschiro
Created November 18, 2018 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orschiro/641e397490a0de9fcd2b97aac40dcf7f to your computer and use it in GitHub Desktop.
Save orschiro/641e397490a0de9fcd2b97aac40dcf7f to your computer and use it in GitHub Desktop.
[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=+30min"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment