blob: d00dfde7fda80803df5b91f2b89f46eb586c64c3 [file] [log] [blame]
Vijay Khemka45269ba2018-12-13 11:07:06 -08001#!/bin/bash
2# Usage of this utility
3function usage() {
Patrick Williams552e93e2021-10-27 10:15:20 -05004 echo "usage: power-util mb [on|off|status|cycle|reset]";
5 echo " power-util sled-cycle"
Vijay Khemka45269ba2018-12-13 11:07:06 -08006}
7
Amithash Prasad645ef292019-03-08 14:24:26 -08008power_off() {
Patrick Williams552e93e2021-10-27 10:15:20 -05009 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 Prasad645ef292019-03-08 14:24:26 -080011}
12
13power_on() {
Patrick Williams552e93e2021-10-27 10:15:20 -050014 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 Prasad645ef292019-03-08 14:24:26 -080016}
17
18power_status() {
Patrick Williams552e93e2021-10-27 10:15:20 -050019 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 Prasad645ef292019-03-08 14:24:26 -080025}
26
27power_reset() {
Patrick Williams552e93e2021-10-27 10:15:20 -050028 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 Prasad645ef292019-03-08 14:24:26 -080030}
31
32sled_cycle() {
Patrick Williams552e93e2021-10-27 10:15:20 -050033 i2cset -y 7 0x45 0xd9 c
Amithash Prasad645ef292019-03-08 14:24:26 -080034}
35
Patrick Williams552e93e2021-10-27 10:15:20 -050036if [ "$1" == "sled-cycle" ]; then
37 echo "SLED_CYCLE starting at $(date)"
38 sled_cycle
39 exit 0;
Vijay Khemka110bb2f2020-02-12 14:51:12 -080040fi
41
Amithash Prasad645ef292019-03-08 14:24:26 -080042if [ $# -lt 2 ]; then
Patrick Williams552e93e2021-10-27 10:15:20 -050043 echo "Total number of parameter=$#"
44 echo "Insufficient parameter"
45 usage;
46 exit 0;
Vijay Khemka45269ba2018-12-13 11:07:06 -080047fi
48
Patrick Williams552e93e2021-10-27 10:15:20 -050049if [ "$1" != "mb" ]; then
50 echo "Invalid parameter1=$1"
51 usage;
52 exit 0;
Vijay Khemka45269ba2018-12-13 11:07:06 -080053fi
54
Patrick Williams552e93e2021-10-27 10:15:20 -050055if [ "$2" = "on" ]; then
56 if [ "$(power_status)" == "off" ]; then
57 power_on
Amithash Prasad645ef292019-03-08 14:24:26 -080058 fi
Patrick Williams552e93e2021-10-27 10:15:20 -050059elif [ "$2" = "off" ]; then
60 if [ "$(power_status)" == "on" ]; then
61 power_off
Amithash Prasad645ef292019-03-08 14:24:26 -080062 fi
Patrick Williams552e93e2021-10-27 10:15:20 -050063elif [ "$2" == "cycle" ]; then
64 if [ "$(power_status)" == "on" ]; then
65 power_off
Amithash Prasad645ef292019-03-08 14:24:26 -080066 else
67 echo "WARNING: Powering on server"
68 fi
Patrick Williams552e93e2021-10-27 10:15:20 -050069 power_on
70elif [ "$2" == "reset" ]; then
71 if [ "$(power_status)" == "on" ]; then
72 power_reset
Amithash Prasad645ef292019-03-08 14:24:26 -080073 else
74 echo "ERROR: Server not powered on"
75 fi
Patrick Williams552e93e2021-10-27 10:15:20 -050076elif [ "$2" == "status" ]; then
77 power_status
Vijay Khemka45269ba2018-12-13 11:07:06 -080078else
Patrick Williams552e93e2021-10-27 10:15:20 -050079 echo "Invalid parameter2=$2"
80 usage;
Vijay Khemka45269ba2018-12-13 11:07:06 -080081fi
82
83exit 0;