mirror of
https://github.com/brezlord/iDRAC7_fan_control.git
synced 2024-11-21 21:17:18 +00:00
Merge pull request #3 from shoaib42/systemd
add service and script, update readme
This commit is contained in:
commit
dd34d4c8cd
28
README.md
28
README.md
@ -54,6 +54,34 @@ Date 04-09-2020 10:24:52
|
||||
|
||||
--> Setting fan speed to 20%
|
||||
```
|
||||
systemd
|
||||
Once you have verified the script is working you can set it to run every 5 minuites via cron. On TrueNAS this can be found under the Tasks menu --> Cron Jobs.
|
||||
|
||||
## Running as a service
|
||||
|
||||
Once the service is up and running, the temprature will be checked every `INTERVAL_SEC` seconds. Fan speed will change if the temprature has changed and warrants a speed change.
|
||||
|
||||
There is a delay before the temprature monitoring begins and is controlled by the variable `INITIAL_START_DELAY_SEC`. After this initial delay the time between checks is governed by the `INTERVAL_SEC` value.
|
||||
|
||||
When the server is shutdown/rebooted or started, the manual control is reset, this is to avoid any left over low fan speeds from previous power outage/powerdown/shutdown etc.
|
||||
|
||||
The files required to run the service are `fan_control_dyn.sh` `fancontrol.service`
|
||||
|
||||
|
||||
Simply execute the following to get the service set up.
|
||||
```
|
||||
sudo cp fan_control_dyn.sh /usr/local/sbin/fan_control_dyn.sh
|
||||
sudo chmod 755 /usr/local/sbin/fan_control_dyn.sh
|
||||
sudo cp fancontrol.service /etc/systemd/system/fancontrol.service
|
||||
sudo systemctl enable fancontrol.service
|
||||
sudo systemctl start fancontrol.service
|
||||
```
|
||||
|
||||
If you are using a location other than `/usr/local/sbin/fan_control_dyn.sh` then you'll need to modify the location in the `fancontrol.service` file as well
|
||||
```
|
||||
ExecStart=/MY_ABSOLUTE_PATH/fan_control_dyn.sh
|
||||
```
|
||||
=======
|
||||
Once you have verified the script is working you can set it to run every 5 minutes via cron.
|
||||
|
||||
On TrueNAS Core this can be found under the Tasks menu --> Cron Jobs.
|
||||
|
84
fan_control_dyn.sh
Normal file
84
fan_control_dyn.sh
Normal file
@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables
|
||||
IDRAC_IP="IP address of iDRAC"
|
||||
IDRAC_USER="user"
|
||||
IDRAC_PASSWORD="passowrd"
|
||||
INTERVAL_SEC=5
|
||||
INITIAL_START_DELAY_SEC=60
|
||||
|
||||
TEMP_THRESHOLD=35
|
||||
TEMP_SENSOR="04h" # Inlet Temp
|
||||
#TEMP_SENSOR="01h" # Exhaust Temp
|
||||
#TEMP_SENSOR="0Eh" # CPU 1 Temp
|
||||
#TEMP_SENSOR="0Fh" # CPU 2 Temp
|
||||
|
||||
FCTRL=0 #disabled, enabled=1
|
||||
LAST_PCT=0
|
||||
|
||||
|
||||
toggle() {
|
||||
ipmitool -I lanplus -H $IDRAC_IP -U $IDRAC_USER -P $IDRAC_PASSWORD raw 0x30 0x30 0x01 $1 2>&1 >/dev/null
|
||||
}
|
||||
|
||||
reset_manual() {
|
||||
toggle 0x01
|
||||
FCTRL=0 #disabled
|
||||
}
|
||||
|
||||
set_manual() {
|
||||
toggle 0x00
|
||||
FCTRL=1 #enabled
|
||||
}
|
||||
|
||||
graceful_exit() {
|
||||
reset_manual
|
||||
exit 0
|
||||
}
|
||||
|
||||
trap graceful_exit SIGINT SIGTERM
|
||||
|
||||
|
||||
# need the reset in case the system boots up with the last set value
|
||||
reset_manual
|
||||
|
||||
#start delay
|
||||
sleep $INITIAL_START_DELAY_SEC
|
||||
|
||||
|
||||
while [ 1 ]
|
||||
do
|
||||
|
||||
# Get temperature from iDARC.
|
||||
T=$(ipmitool -I lanplus -H $IDRAC_IP -U $IDRAC_USER -P $IDRAC_PASSWORD sdr type temperature 2>/dev/null | grep $TEMP_SENSOR | cut -d"|" -f5 | cut -d" " -f2)
|
||||
|
||||
# If ambient temperature is above 35deg C enable dynamic control and exit, if below set manual control.
|
||||
if [[ $T -ge $TEMP_THRESHOLD ]]
|
||||
then
|
||||
if [[ $FCTRL -ne 0 ]]
|
||||
then
|
||||
reset_manual
|
||||
fi
|
||||
else
|
||||
|
||||
# This gives a Percent that is a multiple of 5 for ranges of 5 degC
|
||||
PCT=$(( 5 * ( T / 5 ) ))
|
||||
# Min PCT Allowed is 10
|
||||
PCT=$(( PCT < 10 ? 10 : PCT ))
|
||||
|
||||
|
||||
if [[ $LAST_PCT -ne $PCT ]]
|
||||
then
|
||||
if [[ $FCTRL -eq 0 ]]
|
||||
then
|
||||
set_manual
|
||||
fi
|
||||
PCTHEX=$(printf '0x%02x' $PCT)
|
||||
ipmitool -I lanplus -H $IDRAC_IP -U $IDRAC_USER -P $IDRAC_PASSWORD raw 0x30 0x30 0x02 0xff $PCTHEX 2>&1 >/dev/null
|
||||
LAST_PCT=$PCT
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
sleep $INTERVAL_SEC
|
||||
done
|
20
fancontrol.service
Normal file
20
fancontrol.service
Normal file
@ -0,0 +1,20 @@
|
||||
[Unit]
|
||||
Description=Fan Control script
|
||||
|
||||
StartLimitIntervalSec=14400
|
||||
StartLimitBurst=10
|
||||
|
||||
[Service]
|
||||
Restart=on-abnormal
|
||||
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
ExecStart=/usr/local/sbin/fan_control_dyn.sh
|
||||
|
||||
ProtectSystem=full
|
||||
|
||||
TimeoutStopSec=5s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user