Added gracefull exit function with trap of SIGQUIT, SIGTERM and SIGKILL

This commit is contained in:
tigerblue77 2022-04-13 13:53:37 +02:00
parent 3db2083f1f
commit ce84e2cbed
2 changed files with 32 additions and 9 deletions

View File

@ -1,5 +1,28 @@
#!/bin/bash #!/bin/bash
# Define global functions
apply_Dell_profile () {
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x01
CURRENT_FAN_CONTROL_PROFILE="Dell default dynamic fan control profile"
}
apply_user_profile () {
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x00
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x02 0xff $HEXADECIMAL_FAN_SPEED
CURRENT_FAN_CONTROL_PROFILE="User static fan control profile ($DECIMAL_FAN_SPEED%)"
}
# Prepare traps in case of container exit
gracefull_exit () {
apply_Dell_profile
echo "/!\ WARNING /!\ Container stopped, Dell default dynamic fan control profile applied for safety."
exit 0
}
trap 'gracefull_exit' SIGQUIT SIGKILL SIGTERM
# Prepare, format and define initial variables
#readonly DELL_FRESH_AIR_COMPLIANCE=45 #readonly DELL_FRESH_AIR_COMPLIANCE=45
if [[ $FAN_SPEED == 0x* ]] if [[ $FAN_SPEED == 0x* ]]
@ -11,6 +34,7 @@ else
HEXADECIMAL_FAN_SPEED=$(printf '0x%02x' $FAN_SPEED) HEXADECIMAL_FAN_SPEED=$(printf '0x%02x' $FAN_SPEED)
fi fi
# Log main informations given to the container
echo "Idrac/IPMI host: $IDRAC_HOST" echo "Idrac/IPMI host: $IDRAC_HOST"
if [[ $IDRAC_HOST == "local" ]] if [[ $IDRAC_HOST == "local" ]]
then then
@ -28,6 +52,7 @@ readonly TABLE_HEADER_PRINT_INTERVAL=10
i=$TABLE_HEADER_PRINT_INTERVAL i=$TABLE_HEADER_PRINT_INTERVAL
IS_DELL_PROFILE_APPLIED=true IS_DELL_PROFILE_APPLIED=true
# Start monitoring
while true; do while true; do
DATA=$(ipmitool -I $LOGIN_STRING sdr type temperature | grep degrees) DATA=$(ipmitool -I $LOGIN_STRING sdr type temperature | grep degrees)
INLET_TEMPERATURE=$(echo "$DATA" | grep Inlet | grep -Po '\d{2}' | tail -1) INLET_TEMPERATURE=$(echo "$DATA" | grep Inlet | grep -Po '\d{2}' | tail -1)
@ -42,8 +67,7 @@ while true; do
COMMENT=" -" COMMENT=" -"
if CPU1_OVERHEAT if CPU1_OVERHEAT
then then
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x01 apply_Dell_profile
CURRENT_FAN_CONTROL_PROFILE="Dell default dynamic fan control profile"
if ! $IS_DELL_PROFILE_APPLIED if ! $IS_DELL_PROFILE_APPLIED
then then
@ -58,17 +82,15 @@ while true; do
fi fi
elif CPU2_OVERHEAT elif CPU2_OVERHEAT
then then
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x01 apply_Dell_profile
CURRENT_FAN_CONTROL_PROFILE="Dell default dynamic fan control profile"
if ! $IS_DELL_PROFILE_APPLIED if ! $IS_DELL_PROFILE_APPLIED
then then
IS_DELL_PROFILE_APPLIED=true IS_DELL_PROFILE_APPLIED=true
COMMENT="CPU 2 temperature is too high. Dell default dynamic fan control profile applied." COMMENT="CPU 2 temperature is too high. Dell default dynamic fan control profile applied."
fi fi
else else
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x00 apply_user_profile
ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x02 0xff $HEXADECIMAL_FAN_SPEED
CURRENT_FAN_CONTROL_PROFILE="User static fan control profile ($DECIMAL_FAN_SPEED%)"
if $IS_DELL_PROFILE_APPLIED if $IS_DELL_PROFILE_APPLIED
then then
@ -86,5 +108,6 @@ while true; do
printf "%12s %3d°C %3d°C %3d°C %5d°C %40s %s\n" "$(date +"%d-%m-%y %H:%M:%S")" $INLET_TEMPERATURE $CPU1_TEMPERATURE $CPU2_TEMPERATURE $EXHAUST_TEMPERATURE "$CURRENT_FAN_CONTROL_PROFILE" "$COMMENT" printf "%12s %3d°C %3d°C %3d°C %5d°C %40s %s\n" "$(date +"%d-%m-%y %H:%M:%S")" $INLET_TEMPERATURE $CPU1_TEMPERATURE $CPU2_TEMPERATURE $EXHAUST_TEMPERATURE "$CURRENT_FAN_CONTROL_PROFILE" "$COMMENT"
((i++)) ((i++))
sleep $CHECK_INTERVAL sleep $CHECK_INTERVAL &
wait $!
done done

View File

@ -19,4 +19,4 @@ ENV FAN_SPEED 5
ENV CPU_TEMPERATURE_TRESHOLD 50 ENV CPU_TEMPERATURE_TRESHOLD 50
ENV CHECK_INTERVAL 60 ENV CHECK_INTERVAL 60
CMD /Dell_iDRAC_fan_controller.sh CMD ["/Dell_iDRAC_fan_controller.sh"]