How I used a docker container to adjust the fans from the hdd temp

anto294

Dabbler
Joined
Mar 27, 2023
Messages
11
Hello, everyone,
I recently found a great docker container based on a well-known script for dynamically cooling hard drives.
Below I explain the steps that I took

First we need to configure "lm-sensors" by running the following shell command
sudo sensors-detect
Always press enter, up to "Do you want to add these lines automatically to /etc/modules?"
At this point write yes and press enter again.

Now run:
sudo /etc/init.d/kmod restart

At this point we run the following command, and look for the fans we want to use to cool the hdds. You can slow them down with your finger.
watch sensors

fan.png

Mine are fan1 and fan5.

In order to make this container work, we need to create a symbolic link to /lib/modules. Here is mine (you have to adapt it to your case).
sudo ln -s /mnt/tank/VM/k3s/hddfanmonitor/lib-modules /lib/modules

Now we can finally create our app, adapting it to the docker compose
version: "3"
services:
hddfancontrol:
image: ghcr.io/fightforlife/docker_hddfancontrol:master
restart: unless-stopped
volumes:
- /lib/modules:/lib/modules:ro
privileged: true
cap_add:
- SYS_MODULE
environment:
- DRIVE_FILEPATHS=/dev/sdb1 /dev/sdc1 /dev/sdd1
- FAN_PWM_FILEPATH=/sys/class/hwmon/hwmon2/pwm1 /sys/class/hwmon/hwmon2/pwm2
- FAN_START_VALUE=70 80
- FAN_STOP_VALUE=20 30
- MIN_TEMP=40
- MAX_TEMP=60
- MIN_FAN_SPEED_PRCT=0
- INTERVAL_S=60
- CPU_PROBE_FILEPATH=/sys/devices/platform/coretemp.0/hwmon/hwmon0/tempY_input
- CPU_TEMP_RANGE=50 70
- SPIN_DOWN_TIME_S=900
- VERBOSITY=debug
- LOG_FILEPATH=/var/log/hddfancontrol.log
- TEMP_QUERY_MODE=smartctl #hddtemp,hdparm,drivetemp,smartctl
You can get an idea from these pictures.
docker-container.png

variables1.png

variables2.png

Screenshot 2023-06-26 104046.png

storage.png

cap.png

I hope I have been helpful :)

UPDATE 26/06/2023
The container has been updated. If you have an error in the logs referring to "hddtemp," know that it has been deprecated.
Use an alternative, such as smartctl. Set it as environment variable.
TEMP_QUERY_MODE=smartctl #hddtemp,hdparm,drivetemp,smartctl

Note TrueNAS Scale 23.10+
If you get the error "OSError: [Errno 30] Read-only file system: '/sys/class/hwmon/hwmon2/pwm1_enable'", please enable 'Provide access to node network namespace for the workload'

UPDATE 13/03/2024
If you wish to use the disk name '/dev/disk/*' instead of '/dev/sd*', create a symbolic link to '/dev' as you did before with '/lib/modules'

Screenshot 2024-03-13 191255.png

example: /dev/disk/by-id/wwn-0x50014ee2c03f0711
 
Last edited:

anto294

Dabbler
Joined
Mar 27, 2023
Messages
11
If anyone has a better title in mind for this thread please suggest it.
 

marshes

Cadet
Joined
Jun 25, 2023
Messages
4
hey @anto294 thanks for posting this. I was trying to figure out how to set this up with docker-compose, but never got it working right. I finally patched my kernel so I can consistently read fan values, so this approach should now work.

2 questions for you, 1) why do you need to create a sym link and mount /lib/modules ? Does it ultimately work?

2) how did you get your fan start and stop values? Did you install and then run pwmconfig on the host first?
 

anto294

Dabbler
Joined
Mar 27, 2023
Messages
11
1) /lib/modules is required by container, and yes sym link work. I use it because by default TrueNAS Scale app doesn’t allow you to set a path outside the zpool.

2) Open the container shell and run.
hddfancontrol /dev/sdx /sys/class/hwmon/hwmonX/pwmX -t
Please replace “X” with your parameters.
After some minute the script returns the parameters.
 
Last edited:

Sunoo

Cadet
Joined
Apr 11, 2023
Messages
6
I had this working perfectly until, I believe, the TrueNAS Scale 23.10 upgrade. Now every time it tries to set fan speed I get:

OSError: [Errno 30] Read-only file system: '/sys/class/hwmon/hwmon2/pwm1_enable'

Any ideas? I'm guessing it's a new layer of protection from either Docker or TrueNAS, but I have no idea if it's possible to get past it. Been looking on and off for months.
 

anto294

Dabbler
Joined
Mar 27, 2023
Messages
11
I had this working perfectly until, I believe, the TrueNAS Scale 23.10 upgrade. Now every time it tries to set fan speed I get:

OSError: [Errno 30] Read-only file system: '/sys/class/hwmon/hwmon2/pwm1_enable'

Any ideas? I'm guessing it's a new layer of protection from either Docker or TrueNAS, but I have no idea if it's possible to get past it. Been looking on and off for months.
If you had written earlier, I would have suggested activating 'Provide access to node network namespace for the workload'.
I don't know why, but it solves the problem. I will add it to the guide
 

Sunoo

Cadet
Joined
Apr 11, 2023
Messages
6
That did it! Doesn’t really make sense given the name, but I’ll take it.

And I didn’t reply earlier because I only found this thread yesterday. But I compared our configs and they matched basically perfectly.

Thanks so much for your help!
 

Sunoo

Cadet
Joined
Apr 11, 2023
Messages
6
Now that this is working for me again, I've reverted the few differences I had from your setup, and figured I'd share them, because if I prefer my way, others may too.

I see that you update /etc/modules , I've found that in TrueNAS upgrades, changes to that file often seem to be blown away. However, as the Docker image runs sensor-detect and modprobe at start, this is likely masked when that happens in your setup.

My approach was after running sensor-detect, I added an init script (System Settings -> Advanced -> Init/Shutdown Scripts) that runs modprobe for the modules sensor-detect found:

Screenshot 2024-03-14 at 5.28.43 PM.png

Doing this means you don't need the symlink to /lib/modules or the SYS_MODULE capability. You will see an error in the logs as the container starts because the modprobe it tries to do won't work, but that can safely be ignored.

modprobe: ERROR: missing parameters. See -h.
 
Top