Supermicro Fan Control
Aug 13, 2020
I was inspired by a fan control perl script posted on the FreeNAS forum for Supermicro motherboards. This script will adjust the fan profile based on drive temperature. It is intended to be run as a cronjob every 5 minutes.
#!/usr/local/bin/python3
import re
import subprocess
DRIVE_PREFIX = 'da'
DRIVE_COUNT = 8
MAX_TEMP = 48
THRESHOLD = 1
def get_temp(idx):
p = subprocess.Popen(['smartctl', '-a', '/dev/%s%d' % (DRIVE_PREFIX, idx)], stdout=subprocess.PIPE)
data = p.communicate()
m = re.findall(r'Current Drive Temperature:.*(\d\d) C', data[0].decode('utf-8'))
return int(m[0]) if m else None
def set_speed(val):
subprocess.Popen(['ipmitool', 'raw', '0x30', '0x45', '0x01', '0x0%d' % val]).communicate()
def main():
highest = 0
for x in range(0, DRIVE_COUNT):
t = get_temp(x)
if t and t > highest: highest = t
if highest >= MAX_TEMP:
print('Setting speed to full')
set_speed(1)
elif MAX_TEMP - highest > THRESHOLD:
print('Setting speed to standard')
set_speed(0)
if __name__ == "__main__":
main()