blob: 30fa34cc875862cbd89e09a7a6092d8a2f18175d [file] [log] [blame]
Vijay Khemka45269ba2018-12-13 11:07:06 -08001#!/bin/bash
2# Usage of this utility
3function usage() {
Amithash Prasad645ef292019-03-08 14:24:26 -08004 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() {
9 echo "Shutting down Server $2"
Vijay Khemka591abde2020-01-15 15:42:25 -080010 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() {
14 echo "Powering on Server $2"
Vijay Khemka591abde2020-01-15 15:42:25 -080015 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() {
Vijay Khemka591abde2020-01-15 15:42:25 -080019 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 Prasad645ef292019-03-08 14:24:26 -080021 echo "on"
Vijay Khemka591abde2020-01-15 15:42:25 -080022 else
23 echo "off"
Amithash Prasad645ef292019-03-08 14:24:26 -080024 fi
25}
26
27power_reset() {
28 echo "Reset on server $2"
Vijay Khemka591abde2020-01-15 15:42:25 -080029 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() {
33 i2cset -y 7 0x45 0xd9 c
34}
35
Vijay Khemka110bb2f2020-02-12 14:51:12 -080036if [ $1 == "sled-cycle" ]; then
37 echo "SLED_CYCLE starting at $(date)"
38 sled_cycle
39 exit 0;
40fi
41
Amithash Prasad645ef292019-03-08 14:24:26 -080042if [ $# -lt 2 ]; then
Vijay Khemka45269ba2018-12-13 11:07:06 -080043 echo "Total number of parameter=$#"
44 echo "Insufficient parameter"
45 usage;
46 exit 0;
47fi
48
49if [ $1 != "mb" ]; then
50 echo "Invalid parameter1=$1"
51 usage;
52 exit 0;
53fi
54
Amithash Prasad645ef292019-03-08 14:24:26 -080055if [ $2 = "on" ]; then
56 if [ $(power_status) == "off" ]; then
57 power_on
58 fi
59elif [ $2 = "off" ]; then
60 if [ $(power_status) == "on" ]; then
61 power_off
62 fi
63elif [ $2 == "cycle" ]; then
64 if [ $(power_status) == "on" ]; then
65 power_off
66 else
67 echo "WARNING: Powering on server"
68 fi
69 power_on
70elif [ $2 == "reset" ]; then
71 if [ $(power_status) == "on" ]; then
72 power_reset
73 else
74 echo "ERROR: Server not powered on"
75 fi
76elif [ $2 == "status" ]; then
77 power_status
Vijay Khemka45269ba2018-12-13 11:07:06 -080078else
Amithash Prasad645ef292019-03-08 14:24:26 -080079 echo "Invalid parameter2=$2"
Vijay Khemka45269ba2018-12-13 11:07:06 -080080 usage;
81fi
82
83exit 0;