| #!/bin/bash |
| # Usage of this utility |
| function usage() { |
| echo "usage: power-util mb [on|off|status|cycle|reset]"; |
| echo " power-util sled-cycle" |
| } |
| |
| GPIO_BASE=$(cat /sys/class/gpio/gpio*/base) |
| PWR_GPIO=$(($GPIO_BASE + 32 + 3)) |
| BMC_RDY_GPIO=$(($GPIO_BASE + 144 +1)) |
| PWR_GOOD=$(($GPIO_BASE + 8 + 6)) |
| PWR_RESET=$(($GPIO_BASE + 33)) |
| |
| power_off() { |
| echo "Shutting down Server $2" |
| echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| sleep 1 |
| echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| sleep 6 |
| echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| } |
| |
| power_on() { |
| echo "Powering on Server $2" |
| echo 0 > /sys/class/gpio/gpio${BMC_RDY_GPIO}/value |
| echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| sleep 1 |
| echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| } |
| |
| power_status() { |
| st=$(cat /sys/class/gpio/gpio${PWR_GOOD}/value) |
| if [ "$st" == "0" ]; then |
| echo "off" |
| else |
| echo "on" |
| fi |
| } |
| |
| power_reset() { |
| echo "Reset on server $2" |
| echo 0 > /sys/class/gpio/gpio${PWR_RESET}/value |
| sleep 0.1 |
| echo 1 > /sys/class/gpio/gpio${PWR_RESET}/value |
| } |
| |
| sled_cycle() { |
| i2cset -y 7 0x45 0xd9 c |
| } |
| |
| if [ $# -lt 2 ]; then |
| echo "Total number of parameter=$#" |
| echo "Insufficient parameter" |
| usage; |
| exit 0; |
| fi |
| |
| if [ $1 == "sled-cycle" ]; then |
| sled_cycle |
| fi |
| |
| if [ $1 != "mb" ]; then |
| echo "Invalid parameter1=$1" |
| usage; |
| exit 0; |
| fi |
| |
| if [ $2 = "on" ]; then |
| if [ $(power_status) == "off" ]; then |
| power_on |
| fi |
| elif [ $2 = "off" ]; then |
| if [ $(power_status) == "on" ]; then |
| power_off |
| fi |
| elif [ $2 == "cycle" ]; then |
| if [ $(power_status) == "on" ]; then |
| power_off |
| else |
| echo "WARNING: Powering on server" |
| fi |
| power_on |
| elif [ $2 == "reset" ]; then |
| if [ $(power_status) == "on" ]; then |
| power_reset |
| else |
| echo "ERROR: Server not powered on" |
| fi |
| elif [ $2 == "status" ]; then |
| power_status |
| else |
| echo "Invalid parameter2=$2" |
| usage; |
| fi |
| |
| exit 0; |