add fan control service
This commit is contained in:
10
proxmox/fan_control/fan_control.service
Normal file
10
proxmox/fan_control/fan_control.service
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=User defined temperature fan control for iDrac 9
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/local/sbin/temperature_monitor.sh
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
63
proxmox/fan_control/fan_control.sh
Normal file
63
proxmox/fan_control/fan_control.sh
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
check_start_time() {
|
||||||
|
local start_time="$1"
|
||||||
|
local current_time=$(date +%s)
|
||||||
|
|
||||||
|
local time_diff=$((current_time - start_time))
|
||||||
|
|
||||||
|
if [ $time_diff -ge 60 ]; then
|
||||||
|
echo 0
|
||||||
|
else
|
||||||
|
echo 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_temperature() {
|
||||||
|
temp_lines=$(ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" sdr type temperature 2>/dev/null | grep -e degrees | awk '{print $(NF-2)}')
|
||||||
|
temp_arr=""
|
||||||
|
readarray -t temp_arr <<< "$temp_lines"
|
||||||
|
sorted_temps=($(printf "%s\n" "${temp_arr[@]}" | sort -nr))
|
||||||
|
max_temp=${sorted_temps[0]}
|
||||||
|
|
||||||
|
if [ "$max_temp" -le 60 ]; then
|
||||||
|
# enable manual fan control
|
||||||
|
ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" raw 0x30 0x30 0x01 0x00 &> /dev/null
|
||||||
|
# set initial fan to 20%
|
||||||
|
ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" raw 0x30 0x30 0x02 0xff 0x14 &> /dev/null
|
||||||
|
else
|
||||||
|
# enable Dell fan control
|
||||||
|
ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" raw 0x30 0x30 0x01 0x01 &> /dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
disable_third_party_mode (){
|
||||||
|
# disable 3rd party pcie fan mode
|
||||||
|
output=$(sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$USER@$HOST" "racadm get system.pcieslotlfm" 2>/dev/null)
|
||||||
|
pcie_ports_count=$(echo "$output" | grep -c 'System.pcieslotlfm')
|
||||||
|
|
||||||
|
# Iterate through each PCIe port and disable third party mode
|
||||||
|
for ((i=1; i<=pcie_ports_count; i++)); do
|
||||||
|
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$USER@$HOST" "racadm set system.pcieslotlfm.$i.lfmmode disabled" &> /dev/null
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
HOST=""
|
||||||
|
USER=""
|
||||||
|
PASS=""
|
||||||
|
VMID=""
|
||||||
|
|
||||||
|
start_time=$(ps -o lstart= -p $(cat /var/run/qemu-server/$VMID.pid))
|
||||||
|
start_time=$(date -d "$start_time" +%s)
|
||||||
|
|
||||||
|
while [[ $(check_start_time "$start_time") -eq 1 ]]
|
||||||
|
do
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
disable_third_party_mode
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
check_temperature
|
||||||
|
sleep 60
|
||||||
|
done
|
Reference in New Issue
Block a user