31952c670e4068fc1e7b7e9faa2a7bd631c3bb90 — Tim Morgan 10 months ago 41e11fc
Use systemd instead of circadian
2 files changed, 39 insertions(+), 2 deletions(-)

M README.md
A suspend-to-hibernate.service
M README.md => README.md +14 -2
@@ 59,6 59,18 @@   ## Automatically Hibernate When Idle
  
- I want the tablet to hibernate after a period of inactivity, so I installed and configured [Circadian](https://github.com/mrmekon/circadian).
+ The system should enter a sort of "suspend" state (scare quotes because it's not really actually suspend) which saves some battery, but I wanted the system to hibernate after a longer period of inactivity. Below steps accomplish that:
  
- In Gnome settings, I set the OS to suspend after 2 minutes of inactivity. As I mentioned above, this does not really suspend -- it blanks the screen and maybe disables wifi. Circadian is set to hibernate after 10 minutes of activity to further save the battery.
+ 1. Add the following line to `/lib/systemd/system/suspend.target`:
+ 
+    ```
+    Requires=suspend-to-hibernate.service
+    ```
+ 
+ 1. Copy the `suspend-to-hibernate.service` file in this repo to `/etc/systemd/system/suspend-to-hibernate.service`.
+ 
+ 1. Enable the service:
+ 
+    ```
+    sudo systemctl enable suspend-to-hibernate
+    ```

A suspend-to-hibernate.service => suspend-to-hibernate.service +25 -0
@@ 0,0 1,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