1#!/bin/bash 2 3# Provide source directive to shellcheck. 4# shellcheck source=meta-facebook/meta-greatlakes/recipes-phosphor/state/phosphor-state-manager/power-cmd 5source /usr/libexec/phosphor-state-manager/power-cmd 6 7CHASSIS_ID=$1 8SLOT=$(( $1-1 )) 9OFFSET=$(( 0x9 + SLOT )) 10 11# Server 12v power off 12chassis-power-off() 13{ 14 result=$(i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_OFF_SLOT") 15 echo "$result" 16 sleep 1 17 18 # Check chassis status after doing 12V off 19 chassis_status=$(chassis-power-status $SLOT) 20 if [ "$chassis_status" == "$STATE_OFF" ] 21 then 22 busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF" 23 echo "Chassis is power off" 24 else 25 busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON" 26 echo "Chassis is power on" 27 exit 0; 28 fi 29} 30 31chassis_status=$(chassis-power-status $SLOT) 32if [ "$chassis_status" == "$STATE_UNKNOWN" ] 33then 34 echo "Invalid slot id" 35 exit 1; 36elif [ "$chassis_status" == "$STATE_ON" ] 37then 38 chassis-power-off 39 exit 0; 40else 41 echo "Chassis is already off" 42 exit 0; 43fi 44