The last thing missing is fan control. Note that the monitor script below is only valid for a kernel selected CONFIG_SENSORS_GPIO_FAN=y, otherwise you need to manipulate the GPIO in the user space for fan speed reading and setting. And you need smartctl or hddtemp for the script to actually work.
1. Temperature monitor script. Got from the web (can't remember the url, but the original author's information is in the script. And I'm sure it's initially for WD My Book World Edition) and modified by me.
/usr/local/sbin/temperature-monitor:
Code:
#!/bin/sh
# An alternative temperature monitoring and fan control script for
# WD MyBook World Edition external hard drives
#
# Copyright (C) 2007 by kyyhkynen at gmail.com
#
# You may do with this file (and parts thereof) whatever you want, as long
# as my copyright notice is retained.
# last updated 2008/04/23
#
#120411: Adapted for vanilla kernel patched for LS-WVL/E-AP
#
########################################################
#
# Configuration settings
#
########################################################
# Disk(s) to monitor.
DISK1=sda
DISK2=sdb
# Program location. we'll use HDDTEMP to get the temperature if available, otherwise
# smartctl will be used
HDPARM=$(which hdparm)
HDDTEMP=$(which hddtemp)
SMARTCTL=$(which smartctl)
# Control interfaces
ALARM_LED=/sys/devices/platform/leds-gpio/leds/lswvl:alarm:red
ALARM_LED_TRIGGER=${ALARM_LED}/trigger
ALARM_LED_BRIGHTNESS=${ALARM_LED}/brightness
ALARM_LED_DELAY_ON=${ALARM_LED}/delay_on
ALARM_LED_DELAY_OFF=${ALARM_LED}/delay_off
FAN_CTRL=/sys/devices/platform/gpio-fan
FAN_TARGET=${FAN_CTRL}/fan1_target
FAN_INPUT=${FAN_CTRL}/fan1_input
# (default) temperature limits for speeds.
# When the temperature of the disk(s) is below TEMP_LOW, the fan speed is set to 0
# When the temperature of the disk(s) is above TEMP_LOW, the fan speed is set to 1500
# When the temperature of the disk(s) is above TEMP_HIGH, the fan speed is set to 3250
# When the temperature of the disk(s) goes beyond TEMP_FULL, the fan speed is set to 5000
TEMP_LOW=36
TEMP_HIGH=45
TEMP_FULL=50
# Temperature hysteresis for actually lower-down/stop the fan, i.e. the gap between
# lowering down and speeding up the fan to avoid frequently change of the speed
TEMP_HYS=3
[ -s /etc/default/temp-monitor ] && . /etc/default/temp-monitor
#fan speeds
SPEED_STOP=0
SPEED_LOW=1500
SPEED_HIGH=3250
SPEED_FULL=5000
# Logging stuff
LOG_ENABLED=false
LOG_INTERVAL=1 #in half minute
#LOGGER="echo Temp. monitor:"
LOGGER="/usr/bin/logger -t temp-monitor"
#######################################################################
#
# End of configuration. You shouldn't need to touch lines below this :)
#
#######################################################################
# Device name(s) for the disk(s).
DEV1=/dev/${DISK1}
DEV2=/dev/${DISK2}
# temperature threshold for lower-down/stop the fan
TEMP_STOP=$((TEMP_LOW - TEMP_HYS))
TEMP_DN_LOW=$((TEMP_HIGH - TEMP_HYS))
TEMP_DN_HIGH=$((TEMP_FULL - TEMP_HYS))
hdd_temp()
{
temp=
hdtemp=-274
if [ -n "$HDDTEMP" ]; then
[ -b $DEV1 ] && hdtemp=$($HDDTEMP -n $DEV1)
[ -b $DEV2 ] && {
temp=$($HDDTEMP -n $DEV2)
[ $temp -gt $hdtemp ] && hdtemp=$temp
}
elif [ -n "$SMARTCTL" ]; then
[ -b $DEV1 ] && hdtemp=$($SMARTCTL -d ata -A $DEV1 | grep Tempera | cut -c 88-90)
[ -b $DEV2 ] && {
temp=$($SMARTCTL -d ata -A $DEV2 | grep Tempera | cut -c 88-90)
[ $temp -gt $hdtemp ] && hdtemp=$temp
}
fi
echo "$hdtemp"
}
alarm_blink()
{
if [ $1 = "on" ]; then
echo 1 > $ALARM_LED_BRIGHTNESS #light the alarm led
echo timer > $ALARM_LED_TRIGGER #blink it
echo 333 > $ALARM_LED_DELAY_ON
echo 333 > $ALARM_LED_DELAY_OFF
elif [ $1 = "off" ]; then
echo 0 > $ALARM_LED_BRIGHTNESS #turn off the alarm led
echo none > $ALARM_LED_TRIGGER #restore trigger
fi
}
fan_speed()
{
if [ $1 = "get" ]; then
cat $FAN_INPUT
elif [ $1 = "set" ]; then
echo $2 > $FAN_TARGET
fi
}
HDD_TEMP=$(hdd_temp)
if [ $HDD_TEMP -eq -274 -o ! -d "$FAN_CTRL" ]; then
$LOG_ENABLED && ${LOGGER} "Required program (hddtemp or smartctl), harddisk or fan control interface not found, exit now."
exit 1
fi
# Get current fan speed
fspeed=$(fan_speed get)
log_counter=0
while true; do
if [ $HDD_TEMP -ge $TEMP_FULL ]; then
[ $fspeed -lt $SPEED_FULL ] && fan_speed set $SPEED_FULL
fspeed=$SPEED_FULL
alarm_blink on
else
alarm_blink off
if [ $HDD_TEMP -gt $TEMP_DN_HIGH -a $fspeed -lt $SPEED_FULL ]; then
[ $fspeed -ne $SPEED_HIGH ] && fan_speed set $SPEED_HIGH
fspeed=$SPEED_HIGH
elif [ $HDD_TEMP -ge $TEMP_HIGH ]; then
[ $fspeed -ne $SPEED_HIGH ] && fan_speed set $SPEED_HIGH
fspeed=$SPEED_HIGH
elif [ $HDD_TEMP -gt $TEMP_DN_LOW -a $fspeed -lt $SPEED_HIGH ]; then
[ $fspeed -ne $SPEED_LOW ] && fan_speed set $SPEED_LOW
fspeed=$SPEED_LOW
elif [ $HDD_TEMP -ge $TEMP_LOW ]; then
[ $fspeed -ne $SPEED_LOW ] && fan_speed set $SPEED_LOW
fspeed=$SPEED_LOW
elif [ $HDD_TEMP -gt $TEMP_STOP -a $fspeed -lt $SPEED_LOW ]; then
[ $fspeed -ne $SPEED_STOP ] && fan_speed set $SPEED_STOP
fspeed=$SPEED_STOP
else
[ $fspeed -ne $SPEED_STOP ] && fan_speed set $SPEED_STOP
fspeed=$SPEED_STOP
fi
fi
log_counter=$(( log_counter + 1 ))
if [ $log_counter -ge $((LOG_INTERVAL * 2)) ]; then
$LOG_ENABLED && ${LOGGER} "${HDD_TEMP} ${fspeed}"
log_counter=0
fi
sleep 30
HDD_TEMP=$(hdd_temp)
done
A cleaner solution should place the limit settings under /etc/defaults/temperature-monitor.
2. init script to start the monitor daemon. Use update-rc.d to add this script to the default run levels. Got from the same source as above?
/etc/init.d/temperature-monitor:
Code:
#! /bin/sh
#
# temperature_monitor startup/stop script
# made for WD MyBook World II by kyyhkynen at gmail.com
### BEGIN INIT INFO
# Provides: temperature_mon
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 1 2 3 4 5
# Default-Stop: 0 6
# Short-Description: Start temperature monitor daemon
### END INIT INFO
SVC_NAME="Temperature Monitor"
SVC_SCRIPT=/usr/local/sbin/temperature-monitor
SVC_PID=/var/run/$(basename ${SVC_SCRIPT}).pid
checkconfig() {
if [ ! -r $SVC_SCRIPT ] ; then
echo "$SVC_NAME not found at $SVC_SCRIPT"
return 1
fi
}
start() {
checkconfig || return 1
echo "Starting ${SVC_NAME}"
start-stop-daemon --start --background --quiet \
--pidfile ${SVC_PID} --make-pidfile \
--exec ${SVC_SCRIPT}
}
stop() {
echo "Stopping ${SVC_NAME}"
start-stop-daemon --stop --quiet --pidfile ${SVC_PID}
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
P.S. I just noticed the script contains the original author's mail address. So please DON'T mail to that address, the original script was for WD MYBOOK.