Difference between revisions of "Auto hibernate after suspend"

From Sabayon Wiki
Jump to: navigation, search
(Created page with "The most laptops are configured to suspend after a period of inactivity or when the laptop lid is closed. The standard suspend-to-ram method keeps many functions of the comput...")
 
Line 46: Line 46:
  
  
With this done your computer should go to sleep after 2 hours (as we defined 7200 seconds in the script).
+
With this done your computer should go to hibernation after 2 hours of sleep (as we defined 7200 seconds in the script).

Revision as of 10:18, 18 February 2013

The most laptops are configured to suspend after a period of inactivity or when the laptop lid is closed. The standard suspend-to-ram method keeps many functions of the computer still alive and keeps consuming battery. To avoid running into low battery status while sleeping it would be a good idea to send the computer to hibernate after a defined period.

To get this done we can use rctwake which is a part of the pm-utils package. All we have to do is to add a script in the '/etc/pm/sleep.d' directory. We name the file '0099autohibernate'. The numbers at the start tell the pm-utils that the script is executed first on suspend '00' and on wake '99'.


File: /etc/pm/sleep.d/0099autohibernate
#!/bin/bash
# Script name: /etc/pm/sleep.d/0099autohibernate
# Toggle hibernation after a defined period of sleep

curtime=$(date +%s)

# Define the time until hibernation in seconds
autohibernate=7200

echo "$curtime $1" >>/tmp/autohibernate.log
if [ "$1" = "suspend" ]
then
    # Suspending.  Record current time, and set a wake up timer.
    echo "$curtime" >/var/run/pm-utils/locks/rtchibernate.lock
    rtcwake -m no -s $autohibernate
fi

if [ "$1" = "resume" ]
then
    # Coming out of sleep
    sustime=$(cat /var/run/pm-utils/locks/rtchibernate.lock)
    rm /var/run/pm-utils/locks/rtchibernate.lock
    # Did we wake up due to the rtc timer above?
    if [ $(($curtime - $sustime)) -ge $autohibernate ]
    then
        # Then hibernate
        rm /var/run/pm-utils/locks/pm-suspend.lock
        /usr/sbin/pm-hibernate
    else
        # Otherwise cancel the rtc timer and wake up normally.
        rtcwake -m no -s 1
    fi
fi


Dont forget to set the executable flag for the script.


 chmod +x /etc/pm/sleep.d/0099autohibernate 


With this done your computer should go to hibernation after 2 hours of sleep (as we defined 7200 seconds in the script).