blob: 80f1f69c55de911235f20f3b76267e9f8b31f097 [file] [log] [blame]
Duke Du94311c52019-05-29 09:19:24 +08001#!/bin/bash
2
3# get fan state by d-bus command
4function get_fan_state() {
5 get_property_path='xyz.openbmc_project.Sensor.Threshold.Critical CriticalAlarmLow'
6 fan_state="$(busctl get-property $1 $2 $get_property_path | awk '{print $2}')"
7 echo "$fan_state"
8}
9
10# set fan pwm by d-bus command
11function set_fan_value() {
12 set_property_path='xyz.openbmc_project.Control.FanPwm'
13 busctl set-property $1 $2 $set_property_path Target t 255
14}
15
16fan_tach_path=( '/xyz/openbmc_project/sensors/fan_tach/Fan0_0_RPM'
17 '/xyz/openbmc_project/sensors/fan_tach/Fan0_1_RPM'
18 '/xyz/openbmc_project/sensors/fan_tach/Fan1_0_RPM'
19 '/xyz/openbmc_project/sensors/fan_tach/Fan1_1_RPM'
20 '/xyz/openbmc_project/sensors/fan_tach/Fan2_0_RPM'
21 '/xyz/openbmc_project/sensors/fan_tach/Fan2_1_RPM'
22 )
23
24check_fail_flag=0
25current_fan_state=()
26while true; do
27 hwmon_path="$(mapper get-service ${fan_tach_path[0]})"
28 for i in ${!fan_tach_path[@]};
29 do
30 current_fan_state[$i%2]=$(get_fan_state $hwmon_path ${fan_tach_path[$i]})
31
32 #Compare state of dual rotors with CriticalAlarmLow to check if fan fail
33 if [ ${#current_fan_state[@]} -eq 2 ];then
34 if [ "${current_fan_state[0]}" == "true" ] && \
35 [ "${current_fan_state[1]}" == "true" ] ;then
36 if [ $check_fail_flag -eq 0 ];then
37 systemctl stop phosphor-pid-control
38 for j in ${!fan_tach_path[@]};
39 do
40 #If fan fail is detect, set other fan rpm to pwm 255.
41 set_fan_value $hwmon_path ${fan_tach_path[$j]}
42 check_fail_flag=1
43 done
44 fi
45 current_fan_state=()
46 break
47 fi
48 current_fan_state=()
49 fi
50
51 #fans are going to normal.
52 if [ $i -eq $((${#fan_tach_path[@]}-1)) ] && [ $check_fail_flag -eq 1 ]; then
53 check_fail_flag=0
54 systemctl restart phosphor-pid-control
55 fi
56 done
57 sleep 2
58done