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 | |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 8 | power_off() { |
| 9 | echo "Shutting down Server $2" |
Vijay Khemka | 591abde | 2020-01-15 15:42:25 -0800 | [diff] [blame^] | 10 | busctl set-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.Off |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 11 | } |
| 12 | |
| 13 | power_on() { |
| 14 | echo "Powering on Server $2" |
Vijay Khemka | 591abde | 2020-01-15 15:42:25 -0800 | [diff] [blame^] | 15 | busctl set-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.On |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | power_status() { |
Vijay Khemka | 591abde | 2020-01-15 15:42:25 -0800 | [diff] [blame^] | 19 | st=$(busctl get-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis CurrentPowerState | cut -d"." -f6) |
| 20 | if [ "$st" == "On\"" ]; then |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 21 | echo "on" |
Vijay Khemka | 591abde | 2020-01-15 15:42:25 -0800 | [diff] [blame^] | 22 | else |
| 23 | echo "off" |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 24 | fi |
| 25 | } |
| 26 | |
| 27 | power_reset() { |
| 28 | echo "Reset on server $2" |
Vijay Khemka | 591abde | 2020-01-15 15:42:25 -0800 | [diff] [blame^] | 29 | busctl set-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.Reset |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | sled_cycle() { |
| 33 | i2cset -y 7 0x45 0xd9 c |
| 34 | } |
| 35 | |
| 36 | if [ $# -lt 2 ]; then |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 37 | echo "Total number of parameter=$#" |
| 38 | echo "Insufficient parameter" |
| 39 | usage; |
| 40 | exit 0; |
| 41 | fi |
| 42 | |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 43 | if [ $1 == "sled-cycle" ]; then |
| 44 | sled_cycle |
| 45 | fi |
| 46 | |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 47 | if [ $1 != "mb" ]; then |
| 48 | echo "Invalid parameter1=$1" |
| 49 | usage; |
| 50 | exit 0; |
| 51 | fi |
| 52 | |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 53 | if [ $2 = "on" ]; then |
| 54 | if [ $(power_status) == "off" ]; then |
| 55 | power_on |
| 56 | fi |
| 57 | elif [ $2 = "off" ]; then |
| 58 | if [ $(power_status) == "on" ]; then |
| 59 | power_off |
| 60 | fi |
| 61 | elif [ $2 == "cycle" ]; then |
| 62 | if [ $(power_status) == "on" ]; then |
| 63 | power_off |
| 64 | else |
| 65 | echo "WARNING: Powering on server" |
| 66 | fi |
| 67 | power_on |
| 68 | elif [ $2 == "reset" ]; then |
| 69 | if [ $(power_status) == "on" ]; then |
| 70 | power_reset |
| 71 | else |
| 72 | echo "ERROR: Server not powered on" |
| 73 | fi |
| 74 | elif [ $2 == "status" ]; then |
| 75 | power_status |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 76 | else |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 77 | echo "Invalid parameter2=$2" |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 78 | usage; |
| 79 | fi |
| 80 | |
| 81 | exit 0; |