Qnap debian comes with a mostly finished deamon called qcontrol - which monitors the gpio and controls such things as the triggers for the power switch. Reading around qcontrol is not production ready - it seems to run a lua script, but I tried to do a few things and failed. Time to write a few scripts!
Note: I stuck both these scripts in /usr/local/sbin/ as they require root to be able to run
#!/bin/dash
#Where hddtemp is located
HDDTEMP=/usr/sbin/hddtemp
#List of harddrives
HDDLIST="/dev/sda /dev/sdb"
#Temperature for silent
TEMPSILENT=30
#Temperature for low
TEMPLOW=35
#Temperature for meduim
TEMPMEDIUM=40
#Temperature for fast
TEMPFAST=45
#Hysteriesis for temp
#Set the initial temperature to be 0
TEMPERATURE=0
#Loop through the hard drives and get the highest Temperature
for HDD in $HDDLIST
do
#Test to see if the hard drive exists
if [ ! -e $HDD ]; then
echo $HDD" does not exist skipping"
continue
fi
#Test the hdd
TESTTEMP=$($HDDTEMP $HDD | awk 'BEGIN {FS=":";} {print $3;}' | awk 'BEGIN {FS="°C";} {print $1;}')
if [ $TESTTEMP -ge $TEMPERATURE ]; then
TEMPERATURE=$(($TESTTEMP))
fi
done
#Echo the highest temperature
echo $TEMPERATURE
#Kill exisiting qcontrol instances then start
killall qcontrol 2> /dev/null
rm /var/run/qcontrol.sock 2> /dev/null
/usr/sbin/qcontrol -d 1> /dev/null &
#Wait 1 sec for qcontrol to start
sleep 1
# Now alter the fan based on the temperature
if [ $TEMPERATURE -le $TEMPSILENT ]; then
qcontrol fanspeed silence
elif [ $TEMPERATURE -le $TEMPLOW ]; then
qcontrol fanspeed low
elif [ $TEMPERATURE -le $TEMPMEDIUM ]; then
qcontrol fanspeed medium
else
qcontrol fanspeed fast
fi
exit 0
I called this fanspeed and created another script that called this one every 60 seconds called fancontrol.
#!/bin/sh
while true;
do
#call the fanspeed control
/usr/local/sbin/fanspeed 1> /dev/null
#Sleep for a minute
sleep 60
done
No comments:
Post a Comment