Difference between revisions of "ACPI action script for battery events"
Sewerbeing (Talk | contribs) |
Sewerbeing (Talk | contribs) |
||
Line 11: | Line 11: | ||
# pcfe, 2008-10-28 | # pcfe, 2008-10-28 | ||
− | |||
− | |||
− | |||
− | |||
# spindown time for HD (man hdparm for valid values) | # spindown time for HD (man hdparm for valid values) | ||
Line 36: | Line 32: | ||
if [ "$status" = "off-line" ] | if [ "$status" = "off-line" ] | ||
then | then | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
logger "Running /sbin/laptop_mode start" | logger "Running /sbin/laptop_mode start" | ||
/sbin/laptop_mode start | /sbin/laptop_mode start | ||
− | logger "Setting HD spindown for | + | logger "Setting HD spindown for BATT mode with hdparm -S $ACAD_HD /dev/hda." |
/sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1 | /sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1 | ||
− | logger "Setting HD powersaving for | + | logger "Setting HD powersaving for BATT mode with hdparm -B $ACAD_PM /dev/hda." |
/sbin/hdparm -B $BATT_PM /dev/hda > /dev/null 2>&1 | /sbin/hdparm -B $BATT_PM /dev/hda > /dev/null 2>&1 | ||
+ | logger "Turning off swap." | ||
+ | /sbin/swapoff -a | ||
+ | /usr/bin/cpufreq-set -g conservative | ||
+ | else | ||
+ | logger "Turning on swap." | ||
+ | /sbin/swapon -a | ||
+ | logger "Running /sbin/laptop_mode start" | ||
+ | /sbin/laptop_mode stop | ||
+ | logger "Setting HD spindown for AC mode with hdparm -S $BATT_HD /dev/hda." | ||
+ | /sbin/hdparm -S $ACAD_HD /dev/hda > /dev/null 2>&1 | ||
+ | logger "Setting HD powersaving for AC mode with hdparm -B $BATT_PM /dev/hda." | ||
+ | /sbin/hdparm -B $ACAD_PM /dev/hda > /dev/null 2>&1 | ||
/usr/bin/cpufreq-set -g ondemand | /usr/bin/cpufreq-set -g ondemand | ||
fi | fi | ||
[[Category:Scripts]] | [[Category:Scripts]] |
Revision as of 19:46, 28 October 2008
This is an example ACPI action script that makes Power Management adjustments according to if you are on battery or on AC. Usually this is saved as /etc/acpid/actions/battery.sh.
#!/bin/sh # Tried on Gentoo # cpu throttling is in here it is the cpufreq-set lines # turning swap off is only for those that feel comfortable # doing something this nasty. # comment out the laptop_mode line if you don't have it installed # pcfe, 2008-10-28 # spindown time for HD (man hdparm for valid values) # I prefer 2 hours for acad and 2 min for batt ACAD_HD=244 BATT_HD=24 # Power management level # 255 (off) on AC # 128 (medium) on batt # lowered to 32, pcfe, 2004-06-23 # upped to 64, pcfe, 2004-07-14 # upped to 96, pcfe, 2004-10-20 ACAD_PM=255 BATT_PM=96 # ac/battery event handler status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/AC/state` if [ "$status" = "off-line" ] then logger "Running /sbin/laptop_mode start" /sbin/laptop_mode start logger "Setting HD spindown for BATT mode with hdparm -S $ACAD_HD /dev/hda." /sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1 logger "Setting HD powersaving for BATT mode with hdparm -B $ACAD_PM /dev/hda." /sbin/hdparm -B $BATT_PM /dev/hda > /dev/null 2>&1 logger "Turning off swap." /sbin/swapoff -a /usr/bin/cpufreq-set -g conservative else logger "Turning on swap." /sbin/swapon -a logger "Running /sbin/laptop_mode start" /sbin/laptop_mode stop logger "Setting HD spindown for AC mode with hdparm -S $BATT_HD /dev/hda." /sbin/hdparm -S $ACAD_HD /dev/hda > /dev/null 2>&1 logger "Setting HD powersaving for AC mode with hdparm -B $BATT_PM /dev/hda." /sbin/hdparm -B $ACAD_PM /dev/hda > /dev/null 2>&1 /usr/bin/cpufreq-set -g ondemand fi