You are not logged in.

#1 2011-11-02 00:53:29

Camus
Member
Registered: 2011-07-03
Posts: 71

A little fancontrol hack - sure start & sane fanspeed when stopped

Fancontrol fails to start at boot a lot on my laptop, practically half of the time. I've searched a bit and found out I'm not alone. The only fix I found was to run "sensors -s" before fancontrol, which doesn't work for me either. Some users also complained about fan starting to spin at full speed at shutdowns (speed resets to full speed when fancontrol stops). That annoyed me too.

Anyway, here's how I fixed it:

Making sure fancontrol starts
=================

1) Add this script somewhere on your PATH. I've named it "fancontroller".

#!/bin/bash

if [ "$(whoami)" != "root" ]; then
    echo "You need to be root to do this."
    exit 1
fi

function fancontrol_running() {
    daemons=$(ls /var/run/daemons)
    case $daemons in
        *"fancontrol"*)
            return 0
            ;;
        *)
            return 1
            ;;
    esac
}

until fancontrol_running
do
    rc.d start fancontrol > /dev/null
    sleep 1
done

echo "Fancontrol is running."

exit 0

Change sleep time if you don't feel comfortable with 1 sec interval.

2. ) Run the script in the background at boot (add to /etc/rc.local):

fancontroller &


Prevent fan from spinning at full speed when fancontrol is stopped or when it fails to start
=====================================================
1) Backup /etc/rc.d/fancontrol
2) Change /etc/rc.d/fancontrol like so:

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

PWM_PATH="/sys/class/hwmon/hwmon1/device/pwm1"
SPEED=127

function go_rouge() {
  echo "1" > "${PWM_PATH}_enable"
  sleep 3
  echo "${SPEED}" > "${PWM_PATH}"
}

PID=$(pidof -o %PPID -x /usr/sbin/fancontrol)
case "$1" in
  start)
    stat_busy "Starting fancontrol"
    /usr/bin/sensors -s
    [ -z "$PID" ] && /usr/sbin/fancontrol -D &>/dev/null
    if [ $? -gt 0 -o -n "$PID" ]; then
      stat_fail
    else
      add_daemon fancontrol
      # NON-DEFAULT:
      go_rouge &
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping fancontrol"
    [ ! -z "$PID" ] && kill $PID &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon fancontrol
      # NON-DEFAULT:
      go_rouge &
      stat_done
    fi
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0

Why is go_rogue function also called at fancontrol start? So that fan doesn't spin wildly in case fancontrol fails to start (although it shouldn't with fancontroller script).
If fancontrol does start, then go_rouge doesn't have any effect anyway since fancontrol overwrites pwm file every few seconds.

I hope someone will find this useful.

Last edited by Camus (2011-11-02 00:54:34)

Offline

Board footer

Powered by FluxBB