Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Usage of this utility |
| 3 | function usage() { |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame^] | 4 | echo "usage: power-util mb [on|off|status|cycle|reset]"; |
| 5 | echo " power-util sled-cycle" |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | GPIO_BASE=$(cat /sys/class/gpio/gpio*/base) |
| 9 | PWR_GPIO=$(($GPIO_BASE + 32 + 3)) |
| 10 | BMC_RDY_GPIO=$(($GPIO_BASE + 144 +1)) |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame^] | 11 | PWR_GOOD=$(($GPIO_BASE + 8 + 6)) |
| 12 | PWR_RESET=$(($GPIO_BASE + 33)) |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 13 | |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame^] | 14 | power_off() { |
| 15 | echo "Shutting down Server $2" |
| 16 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 17 | sleep 1 |
| 18 | echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 19 | sleep 6 |
| 20 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 21 | } |
| 22 | |
| 23 | power_on() { |
| 24 | echo "Powering on Server $2" |
| 25 | echo 0 > /sys/class/gpio/gpio${BMC_RDY_GPIO}/value |
| 26 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 27 | echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 28 | sleep 1 |
| 29 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 30 | } |
| 31 | |
| 32 | power_status() { |
| 33 | st=$(cat /sys/class/gpio/gpio${PWR_GOOD}/value) |
| 34 | if [ "$st" == "0" ]; then |
| 35 | echo "off" |
| 36 | else |
| 37 | echo "on" |
| 38 | fi |
| 39 | } |
| 40 | |
| 41 | power_reset() { |
| 42 | echo "Reset on server $2" |
| 43 | echo 0 > /sys/class/gpio/gpio${PWR_RESET}/value |
| 44 | sleep 0.1 |
| 45 | echo 1 > /sys/class/gpio/gpio${PWR_RESET}/value |
| 46 | } |
| 47 | |
| 48 | sled_cycle() { |
| 49 | i2cset -y 7 0x45 0xd9 c |
| 50 | } |
| 51 | |
| 52 | if [ $# -lt 2 ]; then |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 53 | echo "Total number of parameter=$#" |
| 54 | echo "Insufficient parameter" |
| 55 | usage; |
| 56 | exit 0; |
| 57 | fi |
| 58 | |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame^] | 59 | if [ $1 == "sled-cycle" ]; then |
| 60 | sled_cycle |
| 61 | fi |
| 62 | |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 63 | if [ $1 != "mb" ]; then |
| 64 | echo "Invalid parameter1=$1" |
| 65 | usage; |
| 66 | exit 0; |
| 67 | fi |
| 68 | |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame^] | 69 | if [ $2 = "on" ]; then |
| 70 | if [ $(power_status) == "off" ]; then |
| 71 | power_on |
| 72 | fi |
| 73 | elif [ $2 = "off" ]; then |
| 74 | if [ $(power_status) == "on" ]; then |
| 75 | power_off |
| 76 | fi |
| 77 | elif [ $2 == "cycle" ]; then |
| 78 | if [ $(power_status) == "on" ]; then |
| 79 | power_off |
| 80 | else |
| 81 | echo "WARNING: Powering on server" |
| 82 | fi |
| 83 | power_on |
| 84 | elif [ $2 == "reset" ]; then |
| 85 | if [ $(power_status) == "on" ]; then |
| 86 | power_reset |
| 87 | else |
| 88 | echo "ERROR: Server not powered on" |
| 89 | fi |
| 90 | elif [ $2 == "status" ]; then |
| 91 | power_status |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 92 | else |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame^] | 93 | echo "Invalid parameter2=$2" |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 94 | usage; |
| 95 | fi |
| 96 | |
| 97 | exit 0; |