Skip to content

Commit 9f320e5

Browse files
tigerblue77rpbush
andauthored
Add comments for clarity + minor improvements (#39)
* Added comments for clarity. * Updated comments * Update Dell_iDRAC_fan_controller.sh * Added more comments * Improved PR --------- Co-authored-by: Ryan Bush <20880666+rpbush@users.noreply.github.com>
1 parent a3f070f commit 9f320e5

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

Dell_iDRAC_fan_controller.sh

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
#!/bin/bash
22

33
# Define global functions
4-
function apply_Dell_profile () {
5-
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x01 > /dev/null
4+
# This function applies Dell's default dynamic fan control profile
5+
function apply_Dell_fan_control_profile () {
6+
# Use ipmitool to send the raw command to set fan control to Dell default
7+
ipmitool -I $IDRAC_LOGIN_STRING raw 0x30 0x30 0x01 0x01 > /dev/null
68
CURRENT_FAN_CONTROL_PROFILE="Dell default dynamic fan control profile"
79
}
810

9-
function apply_user_profile () {
10-
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x00 > /dev/null
11-
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x02 0xff $HEXADECIMAL_FAN_SPEED > /dev/null
11+
# This function applies a user-specified static fan control profile
12+
function apply_user_fan_control_profile () {
13+
# Use ipmitool to send the raw command to set fan control to user-specified value
14+
ipmitool -I $IDRAC_LOGIN_STRING raw 0x30 0x30 0x01 0x00 > /dev/null
15+
ipmitool -I $IDRAC_LOGIN_STRING raw 0x30 0x30 0x02 0xff $HEXADECIMAL_FAN_SPEED > /dev/null
1216
CURRENT_FAN_CONTROL_PROFILE="User static fan control profile ($DECIMAL_FAN_SPEED%)"
1317
}
1418

1519
function enable_third_party_PCIe_card_Dell_default_cooling_response () {
1620
# We could check the current cooling response before applying but it's not very useful so let's skip the test and apply directly
17-
ipmitool -I $LOGIN_STRING raw 0x30 0xce 0x00 0x16 0x05 0x00 0x00 0x00 0x05 0x00 0x00 0x00 0x00 > /dev/null
21+
ipmitool -I $IDRAC_LOGIN_STRING raw 0x30 0xce 0x00 0x16 0x05 0x00 0x00 0x00 0x05 0x00 0x00 0x00 0x00 > /dev/null
1822
}
1923

2024
function disable_third_party_PCIe_card_Dell_default_cooling_response () {
2125
# We could check the current cooling response before applying but it's not very useful so let's skip the test and apply directly
22-
ipmitool -I $LOGIN_STRING raw 0x30 0xce 0x00 0x16 0x05 0x00 0x00 0x00 0x05 0x00 0x01 0x00 0x00 > /dev/null
26+
ipmitool -I $IDRAC_LOGIN_STRING raw 0x30 0xce 0x00 0x16 0x05 0x00 0x00 0x00 0x05 0x00 0x01 0x00 0x00 > /dev/null
2327
}
2428

2529
# Returns :
2630
# - 0 if third-party PCIe card Dell default cooling response is currently DISABLED
2731
# - 1 if third-party PCIe card Dell default cooling response is currently ENABLED
2832
# - 2 if the current status returned by ipmitool command output is unexpected
2933
# function is_third_party_PCIe_card_Dell_default_cooling_response_disabled() {
30-
# THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE=$(ipmitool -I $LOGIN_STRING raw 0x30 0xce 0x01 0x16 0x05 0x00 0x00 0x00)
34+
# THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE=$(ipmitool -I $IDRAC_LOGIN_STRING raw 0x30 0xce 0x01 0x16 0x05 0x00 0x00 0x00)
3135

3236
# if [ "$THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE" == "16 05 00 00 00 05 00 01 00 00" ]; then
3337
# return 0
@@ -41,18 +45,20 @@ function disable_third_party_PCIe_card_Dell_default_cooling_response () {
4145

4246
# Prepare traps in case of container exit
4347
function gracefull_exit () {
44-
apply_Dell_profile
48+
apply_Dell_fan_control_profile
4549
enable_third_party_PCIe_card_Dell_default_cooling_response
4650
echo "/!\ WARNING /!\ Container stopped, Dell default dynamic fan control profile applied for safety."
4751
exit 0
4852
}
4953

54+
# Trap the signals for container exit and run gracefull_exit function
5055
trap 'gracefull_exit' SIGQUIT SIGKILL SIGTERM
5156

5257
# Prepare, format and define initial variables
5358

54-
#readonly DELL_FRESH_AIR_COMPLIANCE=45
59+
# readonly DELL_FRESH_AIR_COMPLIANCE=45
5560

61+
# Check if FAN_SPEED variable is in hexadecimal format. If not, convert it to hexadecimal
5662
if [[ $FAN_SPEED == 0x* ]]
5763
then
5864
DECIMAL_FAN_SPEED=$(printf '%d' $FAN_SPEED)
@@ -63,72 +69,85 @@ else
6369
fi
6470

6571
# Log main informations given to the container
66-
echo "Idrac/IPMI host: $IDRAC_HOST"
72+
echo "iDRAC/IPMI host: $IDRAC_HOST"
73+
74+
# Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly
6775
if [[ $IDRAC_HOST == "local" ]]
6876
then
69-
LOGIN_STRING='open'
77+
IDRAC_LOGIN_STRING='open'
7078
else
71-
echo "Idrac/IPMI username: $IDRAC_USERNAME"
72-
echo "Idrac/IPMI password: $IDRAC_PASSWORD"
73-
LOGIN_STRING="lanplus -H $IDRAC_HOST -U $IDRAC_USERNAME -P $IDRAC_PASSWORD"
79+
echo "iDRAC/IPMI username: $IDRAC_USERNAME"
80+
echo "iDRAC/IPMI password: $IDRAC_PASSWORD"
81+
IDRAC_LOGIN_STRING="lanplus -H $IDRAC_HOST -U $IDRAC_USERNAME -P $IDRAC_PASSWORD"
7482
fi
83+
84+
# Log the fan speed objective, CPU temperature threshold and check interval
7585
echo "Fan speed objective: $DECIMAL_FAN_SPEED%"
7686
echo "CPU temperature treshold: $CPU_TEMPERATURE_TRESHOLD°C"
7787
echo "Check interval: ${CHECK_INTERVAL}s"
7888
echo ""
7989

80-
# Prepare required variables and constants
90+
# Define the interval for printing
8191
readonly TABLE_HEADER_PRINT_INTERVAL=10
8292
i=$TABLE_HEADER_PRINT_INTERVAL
83-
IS_DELL_PROFILE_APPLIED=true
93+
# Set the flag used to check if the active fan control profile has changed
94+
IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true
8495

8596
# Start monitoring
8697
while true; do
98+
# Sleep for the specified interval before taking another reading
8799
sleep $CHECK_INTERVAL &
88100
SLEEP_PROCESS_PID=$!
89101

90-
DATA=$(ipmitool -I $LOGIN_STRING sdr type temperature | grep degrees)
102+
# Retrieve sensor data using ipmitool
103+
DATA=$(ipmitool -I $IDRAC_LOGIN_STRING sdr type temperature | grep degrees)
91104
INLET_TEMPERATURE=$(echo "$DATA" | grep Inlet | grep -Po '\d{2}' | tail -1)
92105
EXHAUST_TEMPERATURE=$(echo "$DATA" | grep Exhaust | grep -Po '\d{2}' | tail -1)
93106
CPU_DATA=$(echo "$DATA" | grep "3\." | grep -Po '\d{2}')
94107
CPU1_TEMPERATURE=$(echo $CPU_DATA | awk '{print $1;}')
95108
CPU2_TEMPERATURE=$(echo $CPU_DATA | awk '{print $2;}')
96109

97-
CPU1_OVERHEAT () { [ $CPU1_TEMPERATURE -gt $CPU_TEMPERATURE_TRESHOLD ]; }
98-
CPU2_OVERHEAT () { [ $CPU2_TEMPERATURE -gt $CPU_TEMPERATURE_TRESHOLD ]; }
110+
# Define functions to check if CPU 1 and CPU 2 temperatures are above the threshold
111+
function CPU1_OVERHEAT () { [ $CPU1_TEMPERATURE -gt $CPU_TEMPERATURE_TRESHOLD ]; }
112+
function CPU2_OVERHEAT () { [ $CPU2_TEMPERATURE -gt $CPU_TEMPERATURE_TRESHOLD ]; }
99113

114+
# Initialize a variable to store the comments displayed when the fan control profile changed
100115
COMMENT=" -"
116+
# Check if CPU 1 is overheating then apply Dell default dynamic fan control profile if true
101117
if CPU1_OVERHEAT
102118
then
103-
apply_Dell_profile
119+
apply_Dell_fan_control_profile
104120

105-
if ! $IS_DELL_PROFILE_APPLIED
121+
if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED
106122
then
107-
IS_DELL_PROFILE_APPLIED=true
123+
IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true
108124

125+
# Check if CPU 2 is overheating too, Dell default dynamic fan control profile already applied before
109126
if CPU2_OVERHEAT
110127
then
111-
COMMENT="CPU 1 and CPU 2 temperatures are too high. Dell default dynamic fan control profile applied."
128+
COMMENT="CPU 1 and CPU 2 temperatures are too high, Dell default dynamic fan control profile applied for safety"
112129
else
113-
COMMENT="CPU 1 temperature is too high. Dell default dynamic fan control profile applied."
130+
COMMENT="CPU 1 temperature is too high, Dell default dynamic fan control profile applied for safety"
114131
fi
115132
fi
133+
# Check if CPU 2 is overheating then apply Dell default dynamic fan control profile if true
116134
elif CPU2_OVERHEAT
117135
then
118-
apply_Dell_profile
136+
apply_Dell_fan_control_profile
119137

120-
if ! $IS_DELL_PROFILE_APPLIED
138+
if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED
121139
then
122-
IS_DELL_PROFILE_APPLIED=true
123-
COMMENT="CPU 2 temperature is too high. Dell default dynamic fan control profile applied."
140+
IS_DELL_FAN_CONTROL_PROFILE_APPLIED=true
141+
COMMENT="CPU 2 temperature is too high, Dell default dynamic fan control profile applied for safety"
124142
fi
125143
else
126-
apply_user_profile
144+
apply_user_fan_control_profile
127145

128-
if $IS_DELL_PROFILE_APPLIED
146+
# Check if user fan control profile is applied then apply it if not
147+
if $IS_DELL_FAN_CONTROL_PROFILE_APPLIED
129148
then
130-
COMMENT="CPU temperature decreased and is now OK (<= $CPU_TEMPERATURE_TRESHOLD°C). User's fan control profile applied."
131-
IS_DELL_PROFILE_APPLIED=false
149+
IS_DELL_FAN_CONTROL_PROFILE_APPLIED=false
150+
COMMENT="CPU temperature decreased and is now OK (<= $CPU_TEMPERATURE_TRESHOLD°C), user's fan control profile applied."
132151
fi
133152
fi
134153

@@ -143,15 +162,14 @@ while true; do
143162
THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE_STATUS="Enabled"
144163
fi
145164

146-
# Print temperatures array
147-
if [ $i -ge $TABLE_HEADER_PRINT_INTERVAL ]
165+
# Print temperatures, active fan control profile and comment if any change happened during last time interval
166+
if [ $i -eq $TABLE_HEADER_PRINT_INTERVAL ]
148167
then
149-
echo " ------- Temperatures -------"
150-
echo " Date & time Inlet CPU 1 CPU 2 Exhaust Active fan speed profile Third-party PCIe card Dell default cooling response Comment"
168+
echo " ------- Temperatures -------"
169+
echo " Date & time Inlet CPU 1 CPU 2 Exhaust Active fan speed profile Third-party PCIe card Dell default cooling response Comment"
151170
i=0
152171
fi
153-
printf "%12s %3d°C %3d°C %3d°C %5d°C %40s %51s %s\n" "$(date +"%d-%m-%y %H:%M:%S")" $INLET_TEMPERATURE $CPU1_TEMPERATURE $CPU2_TEMPERATURE $EXHAUST_TEMPERATURE "$CURRENT_FAN_CONTROL_PROFILE" "$THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE_STATUS" "$COMMENT"
154-
172+
printf "%19s %3d°C %3d°C %3d°C %5d°C %40s %51s %s\n" "$(date +"%d-%m-%Y %T")" $INLET_TEMPERATURE $CPU1_TEMPERATURE $CPU2_TEMPERATURE $EXHAUST_TEMPERATURE "$CURRENT_FAN_CONTROL_PROFILE" "$THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE_STATUS" "$COMMENT"
155173
((i++))
156174
wait $SLEEP_PROCESS_PID
157175
done

0 commit comments

Comments
 (0)