Minor code structure improvements

This commit is contained in:
Tigerblue77 2024-11-17 21:57:55 +00:00
parent ce7bb3fc9a
commit db64028f2f
3 changed files with 32 additions and 54 deletions

View file

@ -14,8 +14,7 @@ trap 'graceful_exit' SIGINT SIGQUIT SIGTERM
# readonly DELL_FRESH_AIR_COMPLIANCE=45 # readonly DELL_FRESH_AIR_COMPLIANCE=45
# Check if FAN_SPEED variable is in hexadecimal format. If not, convert it to hexadecimal # Check if FAN_SPEED variable is in hexadecimal format. If not, convert it to hexadecimal
if [[ $FAN_SPEED == 0x* ]] if [[ $FAN_SPEED == 0x* ]]; then
then
readonly DECIMAL_FAN_SPEED=$(printf '%d' $FAN_SPEED) readonly DECIMAL_FAN_SPEED=$(printf '%d' $FAN_SPEED)
readonly HEXADECIMAL_FAN_SPEED=$FAN_SPEED readonly HEXADECIMAL_FAN_SPEED=$FAN_SPEED
else else
@ -24,8 +23,7 @@ else
fi fi
# Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly # Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly
if [[ $IDRAC_HOST == "local" ]] if [[ $IDRAC_HOST == "local" ]]; then
then
# Check that the Docker host IPMI device (the iDRAC) has been exposed to the Docker container # Check that the Docker host IPMI device (the iDRAC) has been exposed to the Docker container
if [ ! -e "/dev/ipmi0" ] && [ ! -e "/dev/ipmi/0" ] && [ ! -e "/dev/ipmidev/0" ]; then if [ ! -e "/dev/ipmi0" ] && [ ! -e "/dev/ipmi/0" ] && [ ! -e "/dev/ipmidev/0" ]; then
echo "/!\ Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode. Exiting." >&2 echo "/!\ Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode. Exiting." >&2
@ -40,15 +38,13 @@ fi
get_Dell_server_model get_Dell_server_model
if [[ ! $SERVER_MANUFACTURER == "DELL" ]] if [[ ! $SERVER_MANUFACTURER == "DELL" ]]; then
then
echo "/!\ Your server isn't a Dell product. Exiting." >&2 echo "/!\ Your server isn't a Dell product. Exiting." >&2
exit 1 exit 1
fi fi
# If server model is Gen 14 (*40) or newer # If server model is Gen 14 (*40) or newer
if [[ $SERVER_MODEL =~ .*[RT][[:space:]]?[0-9][4-9]0.* ]] if [[ $SERVER_MODEL =~ .*[RT][[:space:]]?[0-9][4-9]0.* ]]; then
then
DELL_POWEREDGE_GEN_14_OR_NEWER=true DELL_POWEREDGE_GEN_14_OR_NEWER=true
CPU1_TEMPERATURE_INDEX=2 CPU1_TEMPERATURE_INDEX=2
CPU2_TEMPERATURE_INDEX=4 CPU2_TEMPERATURE_INDEX=4
@ -78,19 +74,16 @@ IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true
IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT=true IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT=true
IS_CPU2_TEMPERATURE_SENSOR_PRESENT=true IS_CPU2_TEMPERATURE_SENSOR_PRESENT=true
retrieve_temperatures $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT $IS_CPU2_TEMPERATURE_SENSOR_PRESENT retrieve_temperatures $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT $IS_CPU2_TEMPERATURE_SENSOR_PRESENT
if [ -z "$EXHAUST_TEMPERATURE" ] if [ -z "$EXHAUST_TEMPERATURE" ]; then
then
echo "No exhaust temperature sensor detected." echo "No exhaust temperature sensor detected."
IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT=false IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT=false
fi fi
if [ -z "$CPU2_TEMPERATURE" ] if [ -z "$CPU2_TEMPERATURE" ]; then
then
echo "No CPU2 temperature sensor detected." echo "No CPU2 temperature sensor detected."
IS_CPU2_TEMPERATURE_SENSOR_PRESENT=false IS_CPU2_TEMPERATURE_SENSOR_PRESENT=false
fi fi
# Output new line to beautify output if one of the previous conditions have echoed # Output new line to beautify output if one of the previous conditions have echoed
if ! $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT || ! $IS_CPU2_TEMPERATURE_SENSOR_PRESENT if ! $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT || ! $IS_CPU2_TEMPERATURE_SENSOR_PRESENT; then
then
echo "" echo ""
fi fi
@ -104,38 +97,32 @@ while true; do
# Define functions to check if CPU 1 and CPU 2 temperatures are above the threshold # Define functions to check if CPU 1 and CPU 2 temperatures are above the threshold
function CPU1_OVERHEAT() { [ $CPU1_TEMPERATURE -gt $CPU_TEMPERATURE_THRESHOLD ]; } function CPU1_OVERHEAT() { [ $CPU1_TEMPERATURE -gt $CPU_TEMPERATURE_THRESHOLD ]; }
if $IS_CPU2_TEMPERATURE_SENSOR_PRESENT if $IS_CPU2_TEMPERATURE_SENSOR_PRESENT; then
then
function CPU2_OVERHEAT() { [ $CPU2_TEMPERATURE -gt $CPU_TEMPERATURE_THRESHOLD ]; } function CPU2_OVERHEAT() { [ $CPU2_TEMPERATURE -gt $CPU_TEMPERATURE_THRESHOLD ]; }
fi fi
# Initialize a variable to store the comments displayed when the fan control profile changed # Initialize a variable to store the comments displayed when the fan control profile changed
COMMENT=" -" COMMENT=" -"
# Check if CPU 1 is overheating then apply Dell default dynamic fan control profile if true # Check if CPU 1 is overheating then apply Dell default dynamic fan control profile if true
if CPU1_OVERHEAT if CPU1_OVERHEAT; then
then
apply_Dell_fan_control_profile apply_Dell_fan_control_profile
if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED; then
then
IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true
# If CPU 2 temperature sensor is present, check if it is overheating too. # If CPU 2 temperature sensor is present, check if it is overheating too.
# Do not apply Dell default dynamic fan control profile as it has already been applied before # Do not apply Dell default dynamic fan control profile as it has already been applied before
if $IS_CPU2_TEMPERATURE_SENSOR_PRESENT && CPU2_OVERHEAT if $IS_CPU2_TEMPERATURE_SENSOR_PRESENT && CPU2_OVERHEAT; then
then
COMMENT="CPU 1 and CPU 2 temperatures are too high, Dell default dynamic fan control profile applied for safety" COMMENT="CPU 1 and CPU 2 temperatures are too high, Dell default dynamic fan control profile applied for safety"
else else
COMMENT="CPU 1 temperature is too high, Dell default dynamic fan control profile applied for safety" COMMENT="CPU 1 temperature is too high, Dell default dynamic fan control profile applied for safety"
fi fi
fi fi
# If CPU 2 temperature sensor is present, check if it is overheating then apply Dell default dynamic fan control profile if true # If CPU 2 temperature sensor is present, check if it is overheating then apply Dell default dynamic fan control profile if true
elif $IS_CPU2_TEMPERATURE_SENSOR_PRESENT && CPU2_OVERHEAT elif $IS_CPU2_TEMPERATURE_SENSOR_PRESENT && CPU2_OVERHEAT; then
then
apply_Dell_fan_control_profile apply_Dell_fan_control_profile
if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED; then
then
IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true
COMMENT="CPU 2 temperature is too high, Dell default dynamic fan control profile applied for safety" COMMENT="CPU 2 temperature is too high, Dell default dynamic fan control profile applied for safety"
fi fi
@ -143,20 +130,17 @@ while true; do
apply_user_fan_control_profile apply_user_fan_control_profile
# Check if user fan control profile is applied then apply it if not # Check if user fan control profile is applied then apply it if not
if $IS_DELL_FAN_CONTROL_PROFILE_APPLIED if $IS_DELL_FAN_CONTROL_PROFILE_APPLIED; then
then
IS_DELL_FAN_CONTROL_PROFILE_APPLIED=false IS_DELL_FAN_CONTROL_PROFILE_APPLIED=false
COMMENT="CPU temperature decreased and is now OK (<= $CPU_TEMPERATURE_THRESHOLD°C), user's fan control profile applied." COMMENT="CPU temperature decreased and is now OK (<= $CPU_TEMPERATURE_THRESHOLD°C), user's fan control profile applied."
fi fi
fi fi
# If server model is Gen 14 (*40) or newer # If server model is Gen 14 (*40) or newer
if ! $DELL_POWEREDGE_GEN_14_OR_NEWER if ! $DELL_POWEREDGE_GEN_14_OR_NEWER; then
then
# Enable or disable, depending on the user's choice, third-party PCIe card Dell default cooling response # Enable or disable, depending on the user's choice, third-party PCIe card Dell default cooling response
# No comment will be displayed on the change of this parameter since it is not related to the temperature of any device (CPU, GPU, etc...) but only to the settings made by the user when launching this Docker container # No comment will be displayed on the change of this parameter since it is not related to the temperature of any device (CPU, GPU, etc...) but only to the settings made by the user when launching this Docker container
if $DISABLE_THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE if $DISABLE_THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE; then
then
disable_third_party_PCIe_card_Dell_default_cooling_response disable_third_party_PCIe_card_Dell_default_cooling_response
THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE_STATUS="Disabled" THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE_STATUS="Disabled"
else else
@ -166,8 +150,7 @@ while true; do
fi fi
# Print temperatures, active fan control profile and comment if any change happened during last time interval # Print temperatures, active fan control profile and comment if any change happened during last time interval
if [ $i -eq $TABLE_HEADER_PRINT_INTERVAL ] if [ $i -eq $TABLE_HEADER_PRINT_INTERVAL ]; then
then
echo " ------- Temperatures -------" echo " ------- Temperatures -------"
echo " Date & time Inlet CPU 1 CPU 2 Exhaust Active fan speed profile Third-party PCIe card Dell default cooling response Comment" echo " Date & time Inlet CPU 1 CPU 2 Exhaust Active fan speed profile Third-party PCIe card Dell default cooling response Comment"
i=0 i=0

View file

@ -26,8 +26,7 @@ function convert_decimal_value_to_hexadecimal () {
# Retrieve temperature sensors data using ipmitool # Retrieve temperature sensors data using ipmitool
# Usage : retrieve_temperatures $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT $IS_CPU2_TEMPERATURE_SENSOR_PRESENT # Usage : retrieve_temperatures $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT $IS_CPU2_TEMPERATURE_SENSOR_PRESENT
function retrieve_temperatures() { function retrieve_temperatures() {
if (( $# != 2 )) if (( $# != 2 )); then
then
printf "Illegal number of parameters.\nUsage: retrieve_temperatures \$IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT \$IS_CPU2_TEMPERATURE_SENSOR_PRESENT" >&2 printf "Illegal number of parameters.\nUsage: retrieve_temperatures \$IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT \$IS_CPU2_TEMPERATURE_SENSOR_PRESENT" >&2
return 1 return 1
fi fi
@ -39,8 +38,7 @@ function retrieve_temperatures () {
# Parse CPU data # Parse CPU data
local CPU_DATA=$(echo "$DATA" | grep "3\." | grep -Po '\d{2}') local CPU_DATA=$(echo "$DATA" | grep "3\." | grep -Po '\d{2}')
CPU1_TEMPERATURE=$(echo $CPU_DATA | awk "{print \$$CPU1_TEMPERATURE_INDEX;}") CPU1_TEMPERATURE=$(echo $CPU_DATA | awk "{print \$$CPU1_TEMPERATURE_INDEX;}")
if $IS_CPU2_TEMPERATURE_SENSOR_PRESENT if $IS_CPU2_TEMPERATURE_SENSOR_PRESENT; then
then
CPU2_TEMPERATURE=$(echo $CPU_DATA | awk "{print \$$CPU2_TEMPERATURE_INDEX;}") CPU2_TEMPERATURE=$(echo $CPU_DATA | awk "{print \$$CPU2_TEMPERATURE_INDEX;}")
else else
CPU2_TEMPERATURE="-" CPU2_TEMPERATURE="-"
@ -50,8 +48,7 @@ function retrieve_temperatures () {
INLET_TEMPERATURE=$(echo "$DATA" | grep Inlet | grep -Po '\d{2}' | tail -1) INLET_TEMPERATURE=$(echo "$DATA" | grep Inlet | grep -Po '\d{2}' | tail -1)
# If exhaust temperature sensor is present, parse its temperature data # If exhaust temperature sensor is present, parse its temperature data
if $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT if $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT; then
then
EXHAUST_TEMPERATURE=$(echo "$DATA" | grep Exhaust | grep -Po '\d{2}' | tail -1) EXHAUST_TEMPERATURE=$(echo "$DATA" | grep Exhaust | grep -Po '\d{2}' | tail -1)
else else
EXHAUST_TEMPERATURE="-" EXHAUST_TEMPERATURE="-"
@ -92,8 +89,7 @@ function graceful_exit () {
apply_Dell_fan_control_profile apply_Dell_fan_control_profile
# Reset third-party PCIe card cooling response to Dell default depending on the user's choice at startup # Reset third-party PCIe card cooling response to Dell default depending on the user's choice at startup
if ! $KEEP_THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE_STATE_ON_EXIT if ! $KEEP_THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE_STATE_ON_EXIT; then
then
enable_third_party_PCIe_card_Dell_default_cooling_response enable_third_party_PCIe_card_Dell_default_cooling_response
fi fi

View file

@ -7,8 +7,7 @@
source functions.sh source functions.sh
# Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly # Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly
if [[ $IDRAC_HOST == "local" ]] if [[ $IDRAC_HOST == "local" ]]; then
then
# Check that the Docker host IPMI device (the iDRAC) has been exposed to the Docker container # Check that the Docker host IPMI device (the iDRAC) has been exposed to the Docker container
if [ ! -e "/dev/ipmi0" ] && [ ! -e "/dev/ipmi/0" ] && [ ! -e "/dev/ipmidev/0" ]; then if [ ! -e "/dev/ipmi0" ] && [ ! -e "/dev/ipmi/0" ] && [ ! -e "/dev/ipmidev/0" ]; then
echo "/!\ Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode. Exiting." >&2 echo "/!\ Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode. Exiting." >&2