1
1
#! /bin/bash
2
2
3
3
# 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
6
8
CURRENT_FAN_CONTROL_PROFILE=" Dell default dynamic fan control profile"
7
9
}
8
10
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
12
16
CURRENT_FAN_CONTROL_PROFILE=" User static fan control profile ($DECIMAL_FAN_SPEED %)"
13
17
}
14
18
15
19
function enable_third_party_PCIe_card_Dell_default_cooling_response () {
16
20
# 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
18
22
}
19
23
20
24
function disable_third_party_PCIe_card_Dell_default_cooling_response () {
21
25
# 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
23
27
}
24
28
25
29
# Returns :
26
30
# - 0 if third-party PCIe card Dell default cooling response is currently DISABLED
27
31
# - 1 if third-party PCIe card Dell default cooling response is currently ENABLED
28
32
# - 2 if the current status returned by ipmitool command output is unexpected
29
33
# 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)
31
35
32
36
# if [ "$THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE" == "16 05 00 00 00 05 00 01 00 00" ]; then
33
37
# return 0
@@ -41,18 +45,20 @@ function disable_third_party_PCIe_card_Dell_default_cooling_response () {
41
45
42
46
# Prepare traps in case of container exit
43
47
function gracefull_exit () {
44
- apply_Dell_profile
48
+ apply_Dell_fan_control_profile
45
49
enable_third_party_PCIe_card_Dell_default_cooling_response
46
50
echo " /!\ WARNING /!\ Container stopped, Dell default dynamic fan control profile applied for safety."
47
51
exit 0
48
52
}
49
53
54
+ # Trap the signals for container exit and run gracefull_exit function
50
55
trap ' gracefull_exit' SIGQUIT SIGKILL SIGTERM
51
56
52
57
# Prepare, format and define initial variables
53
58
54
- # readonly DELL_FRESH_AIR_COMPLIANCE=45
59
+ # readonly DELL_FRESH_AIR_COMPLIANCE=45
55
60
61
+ # Check if FAN_SPEED variable is in hexadecimal format. If not, convert it to hexadecimal
56
62
if [[ $FAN_SPEED == 0x* ]]
57
63
then
58
64
DECIMAL_FAN_SPEED=$( printf ' %d' $FAN_SPEED )
63
69
fi
64
70
65
71
# 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
67
75
if [[ $IDRAC_HOST == " local" ]]
68
76
then
69
- LOGIN_STRING =' open'
77
+ IDRAC_LOGIN_STRING =' open'
70
78
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 "
74
82
fi
83
+
84
+ # Log the fan speed objective, CPU temperature threshold and check interval
75
85
echo " Fan speed objective: $DECIMAL_FAN_SPEED %"
76
86
echo " CPU temperature treshold: $CPU_TEMPERATURE_TRESHOLD °C"
77
87
echo " Check interval: ${CHECK_INTERVAL} s"
78
88
echo " "
79
89
80
- # Prepare required variables and constants
90
+ # Define the interval for printing
81
91
readonly TABLE_HEADER_PRINT_INTERVAL=10
82
92
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
84
95
85
96
# Start monitoring
86
97
while true ; do
98
+ # Sleep for the specified interval before taking another reading
87
99
sleep $CHECK_INTERVAL &
88
100
SLEEP_PROCESS_PID=$!
89
101
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)
91
104
INLET_TEMPERATURE=$( echo " $DATA " | grep Inlet | grep -Po ' \d{2}' | tail -1)
92
105
EXHAUST_TEMPERATURE=$( echo " $DATA " | grep Exhaust | grep -Po ' \d{2}' | tail -1)
93
106
CPU_DATA=$( echo " $DATA " | grep " 3\." | grep -Po ' \d{2}' )
94
107
CPU1_TEMPERATURE=$( echo $CPU_DATA | awk ' {print $1;}' )
95
108
CPU2_TEMPERATURE=$( echo $CPU_DATA | awk ' {print $2;}' )
96
109
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 ]; }
99
113
114
+ # Initialize a variable to store the comments displayed when the fan control profile changed
100
115
COMMENT=" -"
116
+ # Check if CPU 1 is overheating then apply Dell default dynamic fan control profile if true
101
117
if CPU1_OVERHEAT
102
118
then
103
- apply_Dell_profile
119
+ apply_Dell_fan_control_profile
104
120
105
- if ! $IS_DELL_PROFILE_APPLIED
121
+ if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED
106
122
then
107
- IS_DELL_PROFILE_APPLIED =true
123
+ IS_DELL_FAN_CONTROL_PROFILE_APPLIED =true
108
124
125
+ # Check if CPU 2 is overheating too, Dell default dynamic fan control profile already applied before
109
126
if CPU2_OVERHEAT
110
127
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 "
112
129
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 "
114
131
fi
115
132
fi
133
+ # Check if CPU 2 is overheating then apply Dell default dynamic fan control profile if true
116
134
elif CPU2_OVERHEAT
117
135
then
118
- apply_Dell_profile
136
+ apply_Dell_fan_control_profile
119
137
120
- if ! $IS_DELL_PROFILE_APPLIED
138
+ if ! $IS_DELL_FAN_CONTROL_PROFILE_APPLIED
121
139
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 "
124
142
fi
125
143
else
126
- apply_user_profile
144
+ apply_user_fan_control_profile
127
145
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
129
148
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. "
132
151
fi
133
152
fi
134
153
@@ -143,15 +162,14 @@ while true; do
143
162
THIRD_PARTY_PCIE_CARD_DELL_DEFAULT_COOLING_RESPONSE_STATUS=" Enabled"
144
163
fi
145
164
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 ]
148
167
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"
151
170
i=0
152
171
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 "
155
173
(( i++ ))
156
174
wait $SLEEP_PROCESS_PID
157
175
done
0 commit comments