blob: 520b1c9913337b57e8d206e37b8a390e48d17694 [file] [log] [blame]
George Hungfe75a9e2020-07-09 21:19:29 +08001#!/bin/bash
2
3##
4 # This script is to handle fan fail condition which is described below.
5 # Fan fail means one fan RPM is under its CriticalLow. If BMC encounters
6 # such situation, then sets other fans to full speed.
7 #
8
9# get fan state
10function get_fan_state() {
11 get_property_path='xyz.openbmc_project.Sensor.Threshold.Critical CriticalAlarmLow'
12 fan_state="$(busctl get-property $1 $2 $get_property_path | awk '{print $2}')"
13 echo "$fan_state"
14}
15
16# check fan fail
17function is_fan_fail() {
18 fan_state=("$@")
19
20 for i in "${fan_state[@]}"
21 do
22 if [ ! -z "$i" ]
23 then
24 if [ $i == "true" ]
25 then
26 echo 1
27 return
28 fi
29 fi
30 done
31 echo 0
32}
33
34fan_tach_path=( '/xyz/openbmc_project/sensors/fan_tach/fan0'
35 '/xyz/openbmc_project/sensors/fan_tach/fan1'
36 '/xyz/openbmc_project/sensors/fan_tach/fan2'
37 '/xyz/openbmc_project/sensors/fan_tach/fan3'
38 '/xyz/openbmc_project/sensors/fan_tach/fan4'
39 )
40
41check_fail_flag=0
42is_fan_fail_flag=0
43current_fan_state=()
44
45while true
46do
47 for i in ${!fan_tach_path[@]}
48 do
49 mapper wait ${fan_tach_path[$i]}
50 hwmon_path="$(mapper get-service ${fan_tach_path[0]})"
51 current_fan_state[$i]=$(get_fan_state $hwmon_path ${fan_tach_path[$i]})
52 done
53
54 is_fan_fail_flag=$(is_fan_fail "${current_fan_state[@]}")
55
56 # if fan fails then set all fans to full speed
57 if [ $is_fan_fail_flag -eq 1 ] && [ $check_fail_flag -eq 0 ]
58 then
59 check_fail_flag=1
60 systemctl stop phosphor-pid-control.service
61
62 # fans recover to normal state
63 elif [ $is_fan_fail_flag -eq 0 ] && [ $check_fail_flag -eq 1 ]
64 then
65 check_fail_flag=0
66 systemctl restart phosphor-pid-control.service
67 fi
68
69 sleep 2
70done