179f697e0SAnthony Wilson#!/bin/sh -e
279f697e0SAnthony Wilson
379f697e0SAnthony Wilsonset -euo pipefail
479f697e0SAnthony Wilson
5189cf248SAnthony WilsonOPTS="bmcstate,bootprogress,chassiskill,chassisoff,chassison,chassisstate,hoststate,\
6a65d30d1SVishwanatha Subbannaosstate,power,poweroff,poweron,state,status,hostrebootoff,hostrebooton,recoveryoff,recoveryon,\
7*295ee4fbSAndrew Geisslerbmcrebootoff, bmcrebooton, listbootblock listlogs"
80f35983dSAnthony Wilson
960c3ac8cSAndrew JefferyUSAGE="Usage: obmcutil [-h] [--wait] [--verbose]
100f35983dSAnthony Wilson                {$OPTS}"
1179f697e0SAnthony Wilson
1279f697e0SAnthony WilsonINTERFACE_ROOT=xyz.openbmc_project
1379f697e0SAnthony WilsonSTATE_INTERFACE=$INTERFACE_ROOT.State
146d3a2c54SVishwanatha SubbannaCONTROL_INTERFACE=$INTERFACE_ROOT.Control
1579f697e0SAnthony Wilson
1679f697e0SAnthony WilsonOBJECT_ROOT=/xyz/openbmc_project
1779f697e0SAnthony WilsonSTATE_OBJECT=$OBJECT_ROOT/state
186d3a2c54SVishwanatha SubbannaCONTROL_OBJECT=$OBJECT_ROOT/control
1979f697e0SAnthony Wilson
207a787dd7SVishwanatha SubbannaHOST_TIMEOUT_TARGET=obmc-host-timeout@0.target
2184b3b29eSVishwanatha SubbannaHOST_CRASH_TARGET=obmc-host-crash@0.target
227a787dd7SVishwanatha Subbanna
23acf54d08SAnthony Wilson## NOTE: The following global variables are used only in the run_timeout cmd.
24acf54d08SAnthony Wilson## By declaring these globally instead of passing them through the
25acf54d08SAnthony Wilson## intermediary functions, which may not be "best practice", the readability
26acf54d08SAnthony Wilson## and cleanliness of the code should at least be increased.
27acf54d08SAnthony Wilson
28acf54d08SAnthony Wilson# The command passed in to be executed (e.g. poweron/off, status, etc.)
29acf54d08SAnthony Wilson# This will be be used in some instances of error reporting
30acf54d08SAnthony WilsonG_ORIG_CMD=
31acf54d08SAnthony Wilson# The state an interface should be in after executing the requested command.
32acf54d08SAnthony WilsonG_REQUESTED_STATE=
33acf54d08SAnthony Wilson# The query to run during a poweron/off or chassison/off to check that
34acf54d08SAnthony Wilson# the requested state (G_REQUESTED_STATE) of the interface has been reached.
35acf54d08SAnthony WilsonG_QUERY=
36acf54d08SAnthony Wilson# Wait the set period of time for state transitions to be successful before
37acf54d08SAnthony Wilson# continuing on with the program or reporting an error if timeout reached.
38acf54d08SAnthony WilsonG_WAIT=
3960c3ac8cSAndrew Jeffery# Print the journal to the console
4060c3ac8cSAndrew JefferyG_VERBOSE=
41acf54d08SAnthony Wilson
42f3f16fa9SAnthony Wilsonprint_help ()
43f3f16fa9SAnthony Wilson{
44f3f16fa9SAnthony Wilson    echo "$USAGE"
45f3f16fa9SAnthony Wilson    echo ""
46f3f16fa9SAnthony Wilson    echo "positional arguments:"
470f35983dSAnthony Wilson    echo "  {$OPTS}"
48f3f16fa9SAnthony Wilson    echo ""
496d3a2c54SVishwanatha Subbanna    echo "Examples:"
506d3a2c54SVishwanatha Subbanna    echo ""
51a65d30d1SVishwanatha Subbanna    echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state"
52a65d30d1SVishwanatha Subbanna    echo "obmcutil hostrebooton  Enable auto reboot of Host from Quiesce state"
53a65d30d1SVishwanatha Subbanna    echo ""
54a65d30d1SVishwanatha Subbanna    echo "obmcutil bmcrebootoff  Disable reboot of BMC"
55a65d30d1SVishwanatha Subbanna    echo "obmcutil bmcrebooton   Enable reboot of BMC"
566d3a2c54SVishwanatha Subbanna    echo ""
5784b3b29eSVishwanatha Subbanna    echo "obmcutil recoveryoff   Disable handling boot watchdog timeout and host crash"
58a65d30d1SVishwanatha Subbanna    echo "                       Also, disable BMC and Host auto reboots"
59a65d30d1SVishwanatha Subbanna    echo ""
6084b3b29eSVishwanatha Subbanna    echo "obmcutil recoveryon    Enable handling boot watchdog timeout and host crash"
61a65d30d1SVishwanatha Subbanna    echo "                       Also, enable BMC and Host auto reboots"
627a787dd7SVishwanatha Subbanna    echo ""
633b7b5619SAndrew Geissler    echo "obmcutil listbootblock Check for and list any errors blocking the boot"
643b7b5619SAndrew Geissler    echo "                       of the system"
653b7b5619SAndrew Geissler    echo ""
66*295ee4fbSAndrew Geissler    echo "obmcutil listlogs      List all phosphor-logging entries on the"
67*295ee4fbSAndrew Geissler    echo "                       system"
68*295ee4fbSAndrew Geissler    echo ""
69f3f16fa9SAnthony Wilson    echo "optional arguments:"
70f3f16fa9SAnthony Wilson    echo "  -h, --help          show this help message and exit"
71acf54d08SAnthony Wilson    echo "  -w, --wait          block until state transition succeeds or fails"
7260c3ac8cSAndrew Jeffery    echo "  -v, --verbose       print the journal to stdout if --wait is supplied"
73f3f16fa9SAnthony Wilson    exit 0
74f3f16fa9SAnthony Wilson}
75f3f16fa9SAnthony Wilson
76acf54d08SAnthony Wilsonrun_timeout ()
77acf54d08SAnthony Wilson{
78acf54d08SAnthony Wilson    local timeout="$1"; shift
79acf54d08SAnthony Wilson    local cmd="$@"
8060c3ac8cSAndrew Jeffery    local verbose_child=
8160c3ac8cSAndrew Jeffery
822869a926SAndrew Jeffery    if [ -n "$G_VERBOSE" ]; then
8360c3ac8cSAndrew Jeffery        journalctl -f &
8460c3ac8cSAndrew Jeffery        verbose_child=$!
8560c3ac8cSAndrew Jeffery    fi
86acf54d08SAnthony Wilson
87acf54d08SAnthony Wilson    $cmd
88acf54d08SAnthony Wilson
89acf54d08SAnthony Wilson    # Run a background query for the transition to the expected state
90acf54d08SAnthony Wilson    # This will be killed if the transition doesn't succeed within
91acf54d08SAnthony Wilson    # a timeout period.
92acf54d08SAnthony Wilson    (
93acf54d08SAnthony Wilson        while ! grep -q $G_REQUESTED_STATE <<< $(handle_cmd $G_QUERY) ; do
94acf54d08SAnthony Wilson            sleep 1
95acf54d08SAnthony Wilson        done
96acf54d08SAnthony Wilson    ) &
9760c3ac8cSAndrew Jeffery    wait_child=$!
98acf54d08SAnthony Wilson
99acf54d08SAnthony Wilson    # Could be bad if process is killed before 'timeout' occurs if
100acf54d08SAnthony Wilson    # transition doesn't succeed.
101acf54d08SAnthony Wilson    trap -- "" SIGTERM
102acf54d08SAnthony Wilson
103acf54d08SAnthony Wilson    # Workaround for lack of 'timeout' command.
104acf54d08SAnthony Wilson    (
105acf54d08SAnthony Wilson        sleep $timeout
10660c3ac8cSAndrew Jeffery        kill $wait_child
107acf54d08SAnthony Wilson    ) > /dev/null 2>&1 &
108acf54d08SAnthony Wilson
10960c3ac8cSAndrew Jeffery    if ! wait $wait_child; then
110acf54d08SAnthony Wilson        echo "Unable to confirm '$G_ORIG_CMD' success" \
111acf54d08SAnthony Wilson        "within timeout period (${timeout}s)"
112acf54d08SAnthony Wilson    fi
11360c3ac8cSAndrew Jeffery
1148be70293SAndrew Jeffery    if [ -n "$verbose_child" ]; then
11560c3ac8cSAndrew Jeffery        kill $verbose_child
11660c3ac8cSAndrew Jeffery    fi
117acf54d08SAnthony Wilson}
118acf54d08SAnthony Wilson
119acf54d08SAnthony Wilsonrun_cmd ()
120acf54d08SAnthony Wilson{
121acf54d08SAnthony Wilson    local cmd="$@";
122acf54d08SAnthony Wilson
123acf54d08SAnthony Wilson    if [ -n "$G_WAIT" ]; then
124acf54d08SAnthony Wilson        run_timeout $G_WAIT "$cmd"
125acf54d08SAnthony Wilson    else
126acf54d08SAnthony Wilson        $cmd
127acf54d08SAnthony Wilson    fi
128acf54d08SAnthony Wilson}
129acf54d08SAnthony Wilson
1303ae0a354SAnthony Wilsonset_property ()
1313ae0a354SAnthony Wilson{
132acf54d08SAnthony Wilson    run_cmd busctl set-property "$@"
1333ae0a354SAnthony Wilson}
1343ae0a354SAnthony Wilson
13579f697e0SAnthony Wilsonget_property ()
13679f697e0SAnthony Wilson{
137acf54d08SAnthony Wilson    G_WAIT=""
138acf54d08SAnthony Wilson    run_cmd busctl get-property "$@"
13979f697e0SAnthony Wilson}
14079f697e0SAnthony Wilson
14179f697e0SAnthony Wilsonstate_query ()
14279f697e0SAnthony Wilson{
14379f697e0SAnthony Wilson    local state=$(get_property "$@" | cut -d '"' -f2)
14479f697e0SAnthony Wilson    printf "%-20s: %s\n" $4 $state
14579f697e0SAnthony Wilson}
14679f697e0SAnthony Wilson
147ea87db40SAnthony Wilsonprint_usage_err ()
148ea87db40SAnthony Wilson{
149ea87db40SAnthony Wilson    echo "ERROR: $1" >&2
150ea87db40SAnthony Wilson    echo "$USAGE"
151ea87db40SAnthony Wilson    exit 1
152ea87db40SAnthony Wilson}
153ea87db40SAnthony Wilson
1547a787dd7SVishwanatha Subbannamask_systemd_target ()
1557a787dd7SVishwanatha Subbanna{
1567a787dd7SVishwanatha Subbanna    target="$@"
1577a787dd7SVishwanatha Subbanna    systemctl mask $target
1587a787dd7SVishwanatha Subbanna}
1597a787dd7SVishwanatha Subbanna
1607a787dd7SVishwanatha Subbannaunmask_systemd_target ()
1617a787dd7SVishwanatha Subbanna{
1627a787dd7SVishwanatha Subbanna    target="$@"
1637a787dd7SVishwanatha Subbanna    systemctl unmask $target
1647a787dd7SVishwanatha Subbanna}
1657a787dd7SVishwanatha Subbanna
166a65d30d1SVishwanatha Subbannadisable_bmc_reboot ()
167a65d30d1SVishwanatha Subbanna{
168a65d30d1SVishwanatha Subbanna    dir="/run/systemd/system/"
169a65d30d1SVishwanatha Subbanna    file="reboot-guard.conf"
170a65d30d1SVishwanatha Subbanna    units=("reboot" "poweroff" "halt")
171a65d30d1SVishwanatha Subbanna
172a65d30d1SVishwanatha Subbanna    for unit in "${units[@]}"; do
173a65d30d1SVishwanatha Subbanna        mkdir -p ${dir}${unit}.target.d
174a65d30d1SVishwanatha Subbanna        echo -e "[Unit]\nRefuseManualStart=yes" >> ${dir}${unit}.target.d/${file}
175a65d30d1SVishwanatha Subbanna    done
176a65d30d1SVishwanatha Subbanna}
177a65d30d1SVishwanatha Subbanna
178a65d30d1SVishwanatha Subbannaenable_bmc_reboot ()
179a65d30d1SVishwanatha Subbanna{
180a65d30d1SVishwanatha Subbanna    dir="/run/systemd/system/"
181a65d30d1SVishwanatha Subbanna    file="reboot-guard.conf"
182a65d30d1SVishwanatha Subbanna    units=("reboot" "poweroff" "halt")
183a65d30d1SVishwanatha Subbanna
184a65d30d1SVishwanatha Subbanna    for unit in "${units[@]}"; do
185a65d30d1SVishwanatha Subbanna        rm -rf ${dir}${unit}.target.d/${file}
186a65d30d1SVishwanatha Subbanna        rm -rf ${dir}${unit}.target.d
187a65d30d1SVishwanatha Subbanna    done
188a65d30d1SVishwanatha Subbanna}
189a65d30d1SVishwanatha Subbanna
1903b7b5619SAndrew Geissler# will write blocking errors to stdout
1913b7b5619SAndrew Geisslercheck_boot_block_errors ()
1923b7b5619SAndrew Geissler{
1933b7b5619SAndrew Geissler    # array of boot block objects
1943b7b5619SAndrew Geissler    blockArray=()
1953b7b5619SAndrew Geissler
1963b7b5619SAndrew Geissler    # Look for any objects under logging that implement the
1973b7b5619SAndrew Geissler    # xyz.openbmc_project.Logging.ErrorBlocksTransition
1983b7b5619SAndrew Geissler    subtree="$(busctl call xyz.openbmc_project.ObjectMapper \
1993b7b5619SAndrew Geissler               /xyz/openbmc_project/object_mapper \
2003b7b5619SAndrew Geissler               xyz.openbmc_project.ObjectMapper \
2013b7b5619SAndrew Geissler               GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \
2023b7b5619SAndrew Geissler               xyz.openbmc_project.Logging.ErrorBlocksTransition)"
2033b7b5619SAndrew Geissler
2043b7b5619SAndrew Geissler    # remove quotation marks
2053b7b5619SAndrew Geissler    subtree="$(echo $subtree | sed 's/\"//g')"
2063b7b5619SAndrew Geissler
2073b7b5619SAndrew Geissler    for entry in $subtree; do
2083b7b5619SAndrew Geissler        if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then
2093b7b5619SAndrew Geissler            blockArray+=( $entry )
2103b7b5619SAndrew Geissler        fi
2113b7b5619SAndrew Geissler    done
2123b7b5619SAndrew Geissler
2133b7b5619SAndrew Geissler    # now find associated error log for each boot block error
2143b7b5619SAndrew Geissler    for berror in "${blockArray[@]}"; do
2153b7b5619SAndrew Geissler        assocs="$(busctl call xyz.openbmc_project.Logging $berror \
2163b7b5619SAndrew Geissler                  org.freedesktop.DBus.Properties Get \
2173b7b5619SAndrew Geissler                  ss xyz.openbmc_project.Association.Definitions Associations)"
2183b7b5619SAndrew Geissler
2193b7b5619SAndrew Geissler        # remove quotation marks
2203b7b5619SAndrew Geissler        assocs="$(echo $assocs | sed 's/\"//g')"
2213b7b5619SAndrew Geissler
2223b7b5619SAndrew Geissler        for entry in $assocs; do
2233b7b5619SAndrew Geissler            if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then
2243b7b5619SAndrew Geissler                echo "Blocking Error: $entry"
2253b7b5619SAndrew Geissler            fi
2263b7b5619SAndrew Geissler        done
2273b7b5619SAndrew Geissler    done
2283b7b5619SAndrew Geissler}
2293b7b5619SAndrew Geissler
230deb6bb45SAndrew Geissler# helper function to check for boot block errors and notify user
231deb6bb45SAndrew Geisslercheck_and_warn_boot_block()
232deb6bb45SAndrew Geissler{
233deb6bb45SAndrew Geissler    blockingErrors=$(check_boot_block_errors)
234deb6bb45SAndrew Geissler    if ! [ -z "$blockingErrors" ]; then
235deb6bb45SAndrew Geissler        echo !!!!!!!!!!
236deb6bb45SAndrew Geissler        echo "WARNING! System has blocking errors that will prevent boot"
237deb6bb45SAndrew Geissler        echo "$blockingErrors"
238deb6bb45SAndrew Geissler        echo !!!!!!!!!!
239deb6bb45SAndrew Geissler    fi
240deb6bb45SAndrew Geissler}
241deb6bb45SAndrew Geissler
242*295ee4fbSAndrew Geissler# list all phosphor-logging entries
243*295ee4fbSAndrew Geisslerlist_logs()
244*295ee4fbSAndrew Geissler{
245*295ee4fbSAndrew Geissler    # Look for any objects under logging that implement the
246*295ee4fbSAndrew Geissler    # xyz.openbmc_project.Logging.Entry
247*295ee4fbSAndrew Geissler    busctl -j call xyz.openbmc_project.ObjectMapper \
248*295ee4fbSAndrew Geissler            /xyz/openbmc_project/object_mapper \
249*295ee4fbSAndrew Geissler            xyz.openbmc_project.ObjectMapper \
250*295ee4fbSAndrew Geissler            GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \
251*295ee4fbSAndrew Geissler            xyz.openbmc_project.Logging.Entry
252*295ee4fbSAndrew Geissler}
253*295ee4fbSAndrew Geissler
25479f697e0SAnthony Wilsonhandle_cmd ()
25579f697e0SAnthony Wilson{
25679f697e0SAnthony Wilson    case "$1" in
2573ae0a354SAnthony Wilson        chassisoff)
2583ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
2593ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2603ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
2613ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
2623ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
263acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.Off
264acf54d08SAnthony Wilson            G_QUERY="chassisstate"
2653ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2663ae0a354SAnthony Wilson            ;;
2673ae0a354SAnthony Wilson        chassison)
268deb6bb45SAndrew Geissler            check_and_warn_boot_block
2693ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
2703ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2713ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
2723ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
2733ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
274acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.On
275acf54d08SAnthony Wilson            G_QUERY="chassisstate"
2763ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2773ae0a354SAnthony Wilson            ;;
2783ae0a354SAnthony Wilson        poweroff)
2793ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
2803ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2813ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
2823ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
2833ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
284acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Off
285acf54d08SAnthony Wilson            G_QUERY="hoststate"
2863ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2873ae0a354SAnthony Wilson            ;;
2883ae0a354SAnthony Wilson        poweron)
289deb6bb45SAndrew Geissler            check_and_warn_boot_block
2903ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
2913ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2923ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
2933ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
2943ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
295acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Running
296acf54d08SAnthony Wilson            G_QUERY="hoststate"
2973ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2983ae0a354SAnthony Wilson            ;;
29979f697e0SAnthony Wilson        bmcstate)
30079f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/bmc0
30179f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
30279f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.BMC
30379f697e0SAnthony Wilson            PROPERTY=CurrentBMCState
30479f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
30579f697e0SAnthony Wilson            ;;
30679f697e0SAnthony Wilson        chassisstate)
30779f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
30879f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
30979f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
31079f697e0SAnthony Wilson            PROPERTY=CurrentPowerState
31179f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
31279f697e0SAnthony Wilson            ;;
31379f697e0SAnthony Wilson        hoststate)
31479f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
31579f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
31679f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
31779f697e0SAnthony Wilson            PROPERTY=CurrentHostState
31879f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
31979f697e0SAnthony Wilson            ;;
32086cffd9cSAlexander Filippov        osstate)
32186cffd9cSAlexander Filippov            OBJECT=$STATE_OBJECT/host0
32286cffd9cSAlexander Filippov            SERVICE=$(mapper get-service $OBJECT)
32386cffd9cSAlexander Filippov            INTERFACE=$STATE_INTERFACE.OperatingSystem.Status
32486cffd9cSAlexander Filippov            PROPERTY=OperatingSystemState
32586cffd9cSAlexander Filippov            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
32686cffd9cSAlexander Filippov            ;;
32779f697e0SAnthony Wilson        state|status)
32886cffd9cSAlexander Filippov            for query in bmcstate chassisstate hoststate bootprogress osstate
32979f697e0SAnthony Wilson            do
33079f697e0SAnthony Wilson                handle_cmd $query
33179f697e0SAnthony Wilson            done
332deb6bb45SAndrew Geissler            check_and_warn_boot_block
33379f697e0SAnthony Wilson            ;;
33450c5f88dSAnthony Wilson        bootprogress)
33550c5f88dSAnthony Wilson            OBJECT=$STATE_OBJECT/host0
33650c5f88dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
33750c5f88dSAnthony Wilson            INTERFACE=$STATE_INTERFACE.Boot.Progress
33850c5f88dSAnthony Wilson            PROPERTY=BootProgress
33950c5f88dSAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
34050c5f88dSAnthony Wilson            ;;
3410f35983dSAnthony Wilson        power)
3420f35983dSAnthony Wilson            OBJECT=/org/openbmc/control/power0
3430f35983dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3440f35983dSAnthony Wilson            INTERFACE=org.openbmc.control.Power
3450f35983dSAnthony Wilson            for property in pgood state pgood_timeout
3460f35983dSAnthony Wilson            do
3470f35983dSAnthony Wilson                # get_property can potentially return several
3480f35983dSAnthony Wilson                # different formats of values, so we do the parsing outside
3490f35983dSAnthony Wilson                # of get_property depending on the query. These queries
3500f35983dSAnthony Wilson                # return 'i VALUE' formatted strings.
3510f35983dSAnthony Wilson                STATE=$(get_property $SERVICE $OBJECT $INTERFACE $property \
3520f35983dSAnthony Wilson                    | sed 's/i[ ^I]*//')
3530f35983dSAnthony Wilson                printf "%s = %s\n" $property $STATE
3540f35983dSAnthony Wilson            done
3550f35983dSAnthony Wilson            ;;
356189cf248SAnthony Wilson        chassiskill)
357189cf248SAnthony Wilson            /usr/libexec/chassiskill
358189cf248SAnthony Wilson            ;;
359a65d30d1SVishwanatha Subbanna        hostrebootoff)
3606d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
3616d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
3626d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
3636d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
3646d3a2c54SVishwanatha Subbanna            VALUE=false
3656d3a2c54SVishwanatha Subbanna            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "b" $VALUE
3666d3a2c54SVishwanatha Subbanna            ;;
367a65d30d1SVishwanatha Subbanna        hostrebooton)
3686d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
3696d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
3706d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
3716d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
3726d3a2c54SVishwanatha Subbanna            VALUE=true
3736d3a2c54SVishwanatha Subbanna            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "b" $VALUE
3746d3a2c54SVishwanatha Subbanna            ;;
375a65d30d1SVishwanatha Subbanna        bmcrebootoff)
376a65d30d1SVishwanatha Subbanna            disable_bmc_reboot
377a65d30d1SVishwanatha Subbanna            ;;
378a65d30d1SVishwanatha Subbanna        bmcrebooton)
379a65d30d1SVishwanatha Subbanna            enable_bmc_reboot
380a65d30d1SVishwanatha Subbanna            ;;
3817a787dd7SVishwanatha Subbanna        recoveryoff)
382a65d30d1SVishwanatha Subbanna            handle_cmd hostrebootoff
383a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebootoff
3847a787dd7SVishwanatha Subbanna            mask_systemd_target $HOST_TIMEOUT_TARGET
38584b3b29eSVishwanatha Subbanna            mask_systemd_target $HOST_CRASH_TARGET
3867a787dd7SVishwanatha Subbanna            ;;
3877a787dd7SVishwanatha Subbanna        recoveryon)
388a65d30d1SVishwanatha Subbanna            handle_cmd hostrebooton
389a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebooton
3907a787dd7SVishwanatha Subbanna            unmask_systemd_target $HOST_TIMEOUT_TARGET
39184b3b29eSVishwanatha Subbanna            unmask_systemd_target $HOST_CRASH_TARGET
3927a787dd7SVishwanatha Subbanna            ;;
3933b7b5619SAndrew Geissler        listbootblock)
3943b7b5619SAndrew Geissler            blockingErrors=$(check_boot_block_errors)
3953b7b5619SAndrew Geissler            if [ -z "$blockingErrors" ]; then
3963b7b5619SAndrew Geissler                echo "No blocking errors present"
3973b7b5619SAndrew Geissler            else
3983b7b5619SAndrew Geissler                echo "$blockingErrors"
3993b7b5619SAndrew Geissler            fi
4003b7b5619SAndrew Geissler            ;;
401*295ee4fbSAndrew Geissler        listlogs)
402*295ee4fbSAndrew Geissler            list_logs
403*295ee4fbSAndrew Geissler            ;;
40479f697e0SAnthony Wilson        *)
405ea87db40SAnthony Wilson            print_usage_err "Invalid command '$1'"
40679f697e0SAnthony Wilson            ;;
40779f697e0SAnthony Wilson    esac
40879f697e0SAnthony Wilson}
40979f697e0SAnthony Wilson
410ea87db40SAnthony Wilsonfor arg in "$@"; do
411ea87db40SAnthony Wilson    case $arg in
412acf54d08SAnthony Wilson        -w|--wait)
413acf54d08SAnthony Wilson            G_WAIT=30
414acf54d08SAnthony Wilson            continue
415acf54d08SAnthony Wilson            ;;
416ea87db40SAnthony Wilson        -h|--help)
417ea87db40SAnthony Wilson            print_help
418ea87db40SAnthony Wilson            ;;
41960c3ac8cSAndrew Jeffery        -v|--verbose)
42060c3ac8cSAndrew Jeffery            G_VERBOSE=y
42160c3ac8cSAndrew Jeffery            ;;
422ea87db40SAnthony Wilson        -*)
423ea87db40SAnthony Wilson            print_usage_err "Unknown option: $arg"
424ea87db40SAnthony Wilson            ;;
425ea87db40SAnthony Wilson        *)
426acf54d08SAnthony Wilson            G_ORIG_CMD=$arg
427ea87db40SAnthony Wilson            handle_cmd $arg
428ea87db40SAnthony Wilson            break
429ea87db40SAnthony Wilson            ;;
430ea87db40SAnthony Wilson    esac
431ea87db40SAnthony Wilsondone
432