summaryrefslogtreecommitdiff
path: root/meta-facebook/recipes-fb/fb-powerctrl/files/power-util
blob: d00dfde7fda80803df5b91f2b89f46eb586c64c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Usage of this utility
function usage() {
    echo "usage: power-util mb [on|off|status|cycle|reset]";
    echo "       power-util sled-cycle"
}

power_off() {
    echo "Shutting down Server"
    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
}

power_on() {
    echo "Powering on Server"
    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
}

power_status() {
    st=$(busctl get-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis CurrentPowerState | cut -d"." -f6)
    if [ "$st" == "On\"" ]; then
        echo "on"
    else
        echo "off"
    fi
}

power_reset() {
    echo "Reset on server"
    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
}

sled_cycle() {
    i2cset -y 7 0x45 0xd9 c
}

if [ "$1" == "sled-cycle" ]; then
    echo "SLED_CYCLE starting at $(date)"
    sled_cycle
    exit 0;
fi

if [ $# -lt 2 ]; then
    echo "Total number of parameter=$#"
    echo "Insufficient parameter"
    usage;
    exit 0;
fi

if [ "$1" != "mb" ]; then
    echo "Invalid parameter1=$1"
    usage;
    exit 0;
fi

if [ "$2" = "on" ]; then
  if [ "$(power_status)" == "off" ]; then
      power_on
  fi
elif [ "$2" = "off" ]; then
  if [ "$(power_status)" == "on" ]; then
      power_off
  fi
elif [ "$2" == "cycle" ]; then
  if [ "$(power_status)" == "on" ]; then
      power_off
  else
    echo "WARNING: Powering on server"
  fi
    power_on
elif [ "$2" == "reset" ]; then
  if [ "$(power_status)" == "on" ]; then
      power_reset
  else
    echo "ERROR: Server not powered on"
  fi
elif [ "$2" == "status" ]; then
    power_status
else
    echo "Invalid parameter2=$2"
    usage;
fi

exit 0;