Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ---------------------------------
- # Fan control script for the LS-WVL
- # ---------------------------------
- # Part of a bigger guide here: http://pastebin.com/H6rEZ5ge
- # ---
- # To recover automatic fan control. If the HDD temperature goes up, so goes the fan.
- # ---
- # Sources: * http://forum.buffalo.nas-central.org/viewtopic.php?f=73&t=25947 (Do not use scripts there, read on)
- # * Email from hato (http://forum.buffalo.nas-central.org/memberlist.php?mode=viewprofile&u=5411)
- # First we install hddtemp
- apt-get update
- apt-get install hddtemp
- nano /usr/local/sbin/temperature-monitor
- # Put this in /usr/local/sbin/temperature-monitor
- #!/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
- # Save with CTRL+O and exit with CTRL+X
- nano /etc/init.d/temperature-monitor
- # Put this in /etc/init.d/temperature-monitor
- #! /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
- # Update rc.d:
- /etc/init.d/update-rc.d temperature-monitor defaults
- # Reboot the device to check if the monitor is started upon boot
- reboot
- ps -A | grep temperature-mon
- # Output should be something like
- # 1348 ? 00:00:00 temperature-mon
- # To check if the temperature monitor is actually doing something, you can turn
- # on the red LED. Within 30 seconds it should turn off again
- echo 1 > /sys/devices/platform/leds-gpio/leds/lswvl\:alarm\:red/brightness
- # You can check the hdd temperature (celcius degree) and current fan speed (rpm):
- hddtemp /dev/sda # Output drive info + temperature
- hddtemp /dev/sdb -n # Only give temperature
- cat /sys/devices/platform/gpio-fan/fan1_input # Fan speed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement