Skip to content

Instantly share code, notes, and snippets.

@ddnomad
Last active May 22, 2024 09:46
Show Gist options
  • Save ddnomad/88f645803f1cc8b12a3ce0f09ba68695 to your computer and use it in GitHub Desktop.
Save ddnomad/88f645803f1cc8b12a3ce0f09ba68695 to your computer and use it in GitHub Desktop.
Ghetto fan control script for Dell PowerEdge servers
#!/usr/bin/env bash
set -euo pipefail
# NOTE: Based on this: https://github.com/NoLooseEnds/Scripts/blob/master/R710-IPMI-TEMP/R710-IPMITemp.sh
# NOTE: Read more: https://www.spxlabs.com/blog/2019/3/16/silence-your-dell-poweredge-server
readonly IPMI_HOST=127.0.0.1
readonly IPMI_USER=root
readonly IPMI_PASSWORD=calvin
readonly IPMI_ENCRYPTION_KEY=0000000000000000000000000000000000000000
readonly HEALTHCHECKSIO_URL=<URL>
readonly AUTO_FALLBACK_TEMP=60
readonly MANUAL_ENABLE_TEMP=40
readonly SLEEP_SECONDS=60
# NOTE: Alternative, more secure approach. Only works if running from the same host.
function run_ipmi_command {
if ! test "$#" -gt 0; then
>&2 echo '---(X) Usage: run_ipmi_command ARGS ...'
exit 1
fi
ipmitool $@
}
function run_ipmi_command_over_ip {
if ! test "$#" -gt 0; then
>&2 echo '---(X) Usage: run_ipmi_command ARGS ...'
exit 1
fi
ipmitool \
-I lanplus \
-H "${IPMI_HOST}" \
-U "${IPMI_USER}" \
-P "${IPMI_PASSWORD}" \
-y "${IPMI_ENCRYPTION_KEY}" \
$@
}
function disable_manual_fan_control {
run_ipmi_command raw 0x30 0x30 0x01 0x01
>&2 echo '---(i) INFO: Disabled manual fan control'
}
function enable_manual_fan_control {
run_ipmi_command_over_ip raw 0x30 0x30 0x01 0x00
run_ipmi_command_over_ip raw 0x30 0x30 0x02 0xff 0x05 # 5%
#run_ipmi_command_over_ip raw 0x30 0x30 0x02 0xff 0x0A # 10%
>&2 echo '---(i) INFO: Enabled manual fan control with 5% offset'
}
function main {
enable_manual_fan_control
while true; do
local current_temp
current_temp="$(
run_ipmi_command_over_ip sdr type temperature | \
cut -f5 -d'|' | \
awk '{ print $1 }' | \
sort -r | \
head -n1
)"
>&2 echo "---(i) INFO: Retrieved current temperature: ${current_temp}"
if test "${current_temp}" -ge "${AUTO_FALLBACK_TEMP}"; then
>&2 echo '---(!) WARNING: Current temperature is too high, disabling manual fan control'
disable_manual_fan_control
elif test "${current_temp}" -le "${MANUAL_ENABLE_TEMP}"; then
>&2 echo '---(i) INFO: Current temperature is normalised, enabled manual fan control'
enable_manual_fan_control
fi
local healthcheckio_resp="$(curl -s "${HEALTHCHECKSIO_URL}")"
>&2 echo "---(i) INFO: Pinged HealthCheckIO: ${healthcheckio_resp}"
>&2 echo "---(+) OK: Finished iteration, sleeping for ${SLEEP_SECONDS}"
sleep "${SLEEP_SECONDS}"
done
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment