Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Usage of this utility |
| 3 | function usage() { |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [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() { |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 9 | echo "Shutting down Server" |
| 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() { |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 14 | echo "Powering on Server" |
| 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() { |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [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 |
| 21 | echo "on" |
| 22 | else |
| 23 | echo "off" |
| 24 | fi |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | power_reset() { |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 28 | echo "Reset on server" |
| 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() { |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 33 | i2cset -y 7 0x45 0xd9 c |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 36 | if [ "$1" == "sled-cycle" ]; then |
| 37 | echo "SLED_CYCLE starting at $(date)" |
| 38 | sled_cycle |
| 39 | exit 0; |
Vijay Khemka | 110bb2f | 2020-02-12 14:51:12 -0800 | [diff] [blame] | 40 | fi |
| 41 | |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 42 | if [ $# -lt 2 ]; then |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 43 | echo "Total number of parameter=$#" |
| 44 | echo "Insufficient parameter" |
| 45 | usage; |
| 46 | exit 0; |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 47 | fi |
| 48 | |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 49 | if [ "$1" != "mb" ]; then |
| 50 | echo "Invalid parameter1=$1" |
| 51 | usage; |
| 52 | exit 0; |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 53 | fi |
| 54 | |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 55 | if [ "$2" = "on" ]; then |
| 56 | if [ "$(power_status)" == "off" ]; then |
| 57 | power_on |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 58 | fi |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 59 | elif [ "$2" = "off" ]; then |
| 60 | if [ "$(power_status)" == "on" ]; then |
| 61 | power_off |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 62 | fi |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 63 | elif [ "$2" == "cycle" ]; then |
| 64 | if [ "$(power_status)" == "on" ]; then |
| 65 | power_off |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 66 | else |
| 67 | echo "WARNING: Powering on server" |
| 68 | fi |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 69 | power_on |
| 70 | elif [ "$2" == "reset" ]; then |
| 71 | if [ "$(power_status)" == "on" ]; then |
| 72 | power_reset |
Amithash Prasad | 645ef29 | 2019-03-08 14:24:26 -0800 | [diff] [blame] | 73 | else |
| 74 | echo "ERROR: Server not powered on" |
| 75 | fi |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 76 | elif [ "$2" == "status" ]; then |
| 77 | power_status |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 78 | else |
Patrick Williams | 552e93e | 2021-10-27 10:15:20 -0500 | [diff] [blame] | 79 | echo "Invalid parameter2=$2" |
| 80 | usage; |
Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 81 | fi |
| 82 | |
| 83 | exit 0; |