DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2010-11-04 03:09:13

bgravato
Member
Registered: 2010-11-04
Posts: 44

fan control using cron

Hi everyone!

I'm new to this forum and recent dns-323 owner. I'm an experienced linux user (been using linux for over a decade) and hoping to contribute my share to help getting the best performance out of this nice piece of hardware.

That said... My first issue with this nas was how to get shell access to it (problem solved by installing ffp). My second issue was on how to change the temperature thresholds for controlling the fan, because I didn't like the factory defaults (unfortunately it seems there's no way of changing this, other than running a different control script).

After reading the wiki, I tried the suggested fan control scripts, to some degree of satisfaction, but decided to make some changes.

I searched the wiki and the forum, but couldn't find any implementation of the script using the cron, so I decided to write my own. Unless you want an update-interval shorter than 1 minute I don't see why not using the cron instead of the while-loop/sleep-time approach.

So this is my fan-cron.sh script in /ffp/start:

Code:

#!/bin/sh

# copy script to rootfs to avoid preventing the disks from spinning down
cp /ffp/bin/fan_ctrl_cron.sh /usr/bin/

# add the fan control script to the current cron list at 1 minute intervals
echo "$(crontab -l;echo '*/1 * * * * /usr/bin/fan_ctrl_cron.sh')"|crontab -

This will work with the fan_ctrl.sh script on the wiki, provided that you remove the while loop and the sleep command (and, of course, in the above code change fan_ctrl_cron.sh to fan_ctrl.sh, or whatever you called it).

This is my fan_ctrl_cron.sh script:

Code:

#!/bin/sh
#
# Script to control the fan speed on a D-Link DNS-323
#
# Note: This script is intended to be ran from the cron
#
# Author: Bruno Gravato
#
# version: 1.0
#

PATH=/usr/bin:/bin:/usr/sbin:/sbin

# kill original fancontrol daemon
PID=`pidof fancontrol`   
if [ "$PID" != "" ]   
then
  kill -9 $PID   
fi

# variables (temperatures are in Fahrenheit)
#
# fan will stop when temperature reaches this value
TEMP_STOP=96
# fan will spin at low speed when temperature reaches this value 
TEMP_LOW=104
# fan will spin at high speed when temperature reaches this value
TEMP_HIGH=113
# this is fan's rpm (rotations per minute) reference point to determine
# wether the fan is rotating at high or low speed
RPM_REF=4000

# get current temperature and fan speed
TEMP=$(temperature g 0)
TEMP=${TEMP##*=}
SPEED=$(fanspeed g)

# check fan speed
if [ $SPEED -lt 1 ]
    # fan is stopped
then
    if [ $TEMP -ge $TEMP_HIGH ]
    then
        # set high speed
        fanspeed h
    elif [ $TEMP -ge $TEMP_LOW ]
    then
        # set low speed
        fanspeed l
    fi
else
    # fan is spinning
    if [ $TEMP -le $TEMP_STOP ]
    then
        # stop the fan
        fanspeed s
    elif [ $SPEED -lt $RPM_REF ]
        # fan at low speed
    then
        if [ $TEMP -ge $TEMP_HIGH ]
        then
            # set high speed
            fanspeed h
        fi
    else
        # fan at high speed
        if [ $TEMP -le $TEMP_LOW ]
        then
            # set low speed
            fanspeed l
        fi
    fi
fi

My DNS-323 is revision B1, but I wrote this so that it will work on C1 too.

Possible changes to make it simpler: move the code for killing the original fancontrol daemon to the start script, since it shouldn't be necessary to check that all the time...

Feel free to use or change this scripts the way it better fits your needs. You may also post it on the wiki if you feel it could be of any interest.

Edit: I forgot to say that all this was done/tested with ffp 0.5 installed.

Cheers,
Bruno

Last edited by bgravato (2010-11-04 03:13:50)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB