1*b2398200SPatrick Williams#!/bin/bash -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,\
742f2898dSAndrew Geisslerbmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs"
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"
523191be88SAndrew Geissler    echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from"
533191be88SAndrew Geissler    echo "                              Quiesce state for a single boot"
54a65d30d1SVishwanatha Subbanna    echo "obmcutil hostrebooton  Enable auto reboot of Host from Quiesce state"
55a65d30d1SVishwanatha Subbanna    echo ""
56a65d30d1SVishwanatha Subbanna    echo "obmcutil bmcrebootoff  Disable reboot of BMC"
57a65d30d1SVishwanatha Subbanna    echo "obmcutil bmcrebooton   Enable reboot of BMC"
586d3a2c54SVishwanatha Subbanna    echo ""
5984b3b29eSVishwanatha Subbanna    echo "obmcutil recoveryoff   Disable handling boot watchdog timeout and host crash"
60a65d30d1SVishwanatha Subbanna    echo "                       Also, disable BMC and Host auto reboots"
61a65d30d1SVishwanatha Subbanna    echo ""
6284b3b29eSVishwanatha Subbanna    echo "obmcutil recoveryon    Enable handling boot watchdog timeout and host crash"
63a65d30d1SVishwanatha Subbanna    echo "                       Also, enable BMC and Host auto reboots"
647a787dd7SVishwanatha Subbanna    echo ""
653b7b5619SAndrew Geissler    echo "obmcutil listbootblock Check for and list any errors blocking the boot"
663b7b5619SAndrew Geissler    echo "                       of the system"
673b7b5619SAndrew Geissler    echo ""
68295ee4fbSAndrew Geissler    echo "obmcutil listlogs      List all phosphor-logging entries on the"
69295ee4fbSAndrew Geissler    echo "                       system"
70295ee4fbSAndrew Geissler    echo ""
71d8c63204SAndrew Geissler    echo "obmcutil showlog <log> Display details of input log. Format of <log>"
72d8c63204SAndrew Geissler    echo "                       should match listlogs output"
73d8c63204SAndrew Geissler    echo ""
7442f2898dSAndrew Geissler    echo "obmcutil deletelogs    Delete all phosphor-logging entries from"
7542f2898dSAndrew Geissler    echo "                       system"
7642f2898dSAndrew Geissler    echo ""
77d8779cd8SAndrew Geissler    echo "optional arguments (must precede the positional options above):"
78f3f16fa9SAnthony Wilson    echo "  -h, --help          show this help message and exit"
79acf54d08SAnthony Wilson    echo "  -w, --wait          block until state transition succeeds or fails"
8060c3ac8cSAndrew Jeffery    echo "  -v, --verbose       print the journal to stdout if --wait is supplied"
81f3f16fa9SAnthony Wilson    exit 0
82f3f16fa9SAnthony Wilson}
83f3f16fa9SAnthony Wilson
84acf54d08SAnthony Wilsonrun_timeout ()
85acf54d08SAnthony Wilson{
86acf54d08SAnthony Wilson    local timeout="$1"; shift
87*b2398200SPatrick Williams    local cmd="$*"
8860c3ac8cSAndrew Jeffery    local verbose_child=
8960c3ac8cSAndrew Jeffery
902869a926SAndrew Jeffery    if [ -n "$G_VERBOSE" ]; then
9160c3ac8cSAndrew Jeffery        journalctl -f &
9260c3ac8cSAndrew Jeffery        verbose_child=$!
9360c3ac8cSAndrew Jeffery    fi
94acf54d08SAnthony Wilson
95acf54d08SAnthony Wilson    $cmd
96acf54d08SAnthony Wilson
97acf54d08SAnthony Wilson    # Run a background query for the transition to the expected state
98acf54d08SAnthony Wilson    # This will be killed if the transition doesn't succeed within
99acf54d08SAnthony Wilson    # a timeout period.
100acf54d08SAnthony Wilson    (
101*b2398200SPatrick Williams        while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do
102acf54d08SAnthony Wilson            sleep 1
103acf54d08SAnthony Wilson        done
104acf54d08SAnthony Wilson    ) &
10560c3ac8cSAndrew Jeffery    wait_child=$!
106acf54d08SAnthony Wilson
107acf54d08SAnthony Wilson    # Could be bad if process is killed before 'timeout' occurs if
108acf54d08SAnthony Wilson    # transition doesn't succeed.
109acf54d08SAnthony Wilson    trap -- "" SIGTERM
110acf54d08SAnthony Wilson
111acf54d08SAnthony Wilson    # Workaround for lack of 'timeout' command.
112acf54d08SAnthony Wilson    (
113*b2398200SPatrick Williams        sleep "$timeout"
11460c3ac8cSAndrew Jeffery        kill $wait_child
115acf54d08SAnthony Wilson    ) > /dev/null 2>&1 &
116acf54d08SAnthony Wilson
11760c3ac8cSAndrew Jeffery    if ! wait $wait_child; then
118acf54d08SAnthony Wilson        echo "Unable to confirm '$G_ORIG_CMD' success" \
119acf54d08SAnthony Wilson        "within timeout period (${timeout}s)"
120acf54d08SAnthony Wilson    fi
12160c3ac8cSAndrew Jeffery
1228be70293SAndrew Jeffery    if [ -n "$verbose_child" ]; then
12360c3ac8cSAndrew Jeffery        kill $verbose_child
12460c3ac8cSAndrew Jeffery    fi
125acf54d08SAnthony Wilson}
126acf54d08SAnthony Wilson
127acf54d08SAnthony Wilsonrun_cmd ()
128acf54d08SAnthony Wilson{
129*b2398200SPatrick Williams    local cmd="$*";
130acf54d08SAnthony Wilson
131acf54d08SAnthony Wilson    if [ -n "$G_WAIT" ]; then
132*b2398200SPatrick Williams        run_timeout "$G_WAIT" "$cmd"
133acf54d08SAnthony Wilson    else
134acf54d08SAnthony Wilson        $cmd
135acf54d08SAnthony Wilson    fi
136acf54d08SAnthony Wilson}
137acf54d08SAnthony Wilson
1383ae0a354SAnthony Wilsonset_property ()
1393ae0a354SAnthony Wilson{
140acf54d08SAnthony Wilson    run_cmd busctl set-property "$@"
1413ae0a354SAnthony Wilson}
1423ae0a354SAnthony Wilson
14379f697e0SAnthony Wilsonget_property ()
14479f697e0SAnthony Wilson{
145acf54d08SAnthony Wilson    G_WAIT=""
146acf54d08SAnthony Wilson    run_cmd busctl get-property "$@"
14779f697e0SAnthony Wilson}
14879f697e0SAnthony Wilson
14979f697e0SAnthony Wilsonstate_query ()
15079f697e0SAnthony Wilson{
151*b2398200SPatrick Williams    local state
152*b2398200SPatrick Williams    state=$(get_property "$@" | cut -d '"' -f2)
153*b2398200SPatrick Williams    printf "%-20s: %s\n" "$4" "$state"
15479f697e0SAnthony Wilson}
15579f697e0SAnthony Wilson
156ea87db40SAnthony Wilsonprint_usage_err ()
157ea87db40SAnthony Wilson{
158ea87db40SAnthony Wilson    echo "ERROR: $1" >&2
159ea87db40SAnthony Wilson    echo "$USAGE"
160ea87db40SAnthony Wilson    exit 1
161ea87db40SAnthony Wilson}
162ea87db40SAnthony Wilson
1637a787dd7SVishwanatha Subbannamask_systemd_target ()
1647a787dd7SVishwanatha Subbanna{
165*b2398200SPatrick Williams    target="$*"
166*b2398200SPatrick Williams    systemctl mask "$target"
1677a787dd7SVishwanatha Subbanna}
1687a787dd7SVishwanatha Subbanna
1697a787dd7SVishwanatha Subbannaunmask_systemd_target ()
1707a787dd7SVishwanatha Subbanna{
171*b2398200SPatrick Williams    target="$*"
172*b2398200SPatrick Williams    systemctl unmask "$target"
1737a787dd7SVishwanatha Subbanna}
1747a787dd7SVishwanatha Subbanna
175a65d30d1SVishwanatha Subbannadisable_bmc_reboot ()
176a65d30d1SVishwanatha Subbanna{
177a65d30d1SVishwanatha Subbanna    dir="/run/systemd/system/"
178a65d30d1SVishwanatha Subbanna    file="reboot-guard.conf"
179a65d30d1SVishwanatha Subbanna    units=("reboot" "poweroff" "halt")
180a65d30d1SVishwanatha Subbanna
181a65d30d1SVishwanatha Subbanna    for unit in "${units[@]}"; do
182*b2398200SPatrick Williams        mkdir -p "${dir}${unit}.target.d"
183*b2398200SPatrick Williams        echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}"
184a65d30d1SVishwanatha Subbanna    done
185a65d30d1SVishwanatha Subbanna}
186a65d30d1SVishwanatha Subbanna
187a65d30d1SVishwanatha Subbannaenable_bmc_reboot ()
188a65d30d1SVishwanatha Subbanna{
189a65d30d1SVishwanatha Subbanna    dir="/run/systemd/system/"
190a65d30d1SVishwanatha Subbanna    file="reboot-guard.conf"
191a65d30d1SVishwanatha Subbanna    units=("reboot" "poweroff" "halt")
192a65d30d1SVishwanatha Subbanna
193a65d30d1SVishwanatha Subbanna    for unit in "${units[@]}"; do
194*b2398200SPatrick Williams        rm -rf "${dir}${unit}.target.d/${file}"
195*b2398200SPatrick Williams        rm -rf "${dir}${unit}.target.d"
196a65d30d1SVishwanatha Subbanna    done
197a65d30d1SVishwanatha Subbanna}
198a65d30d1SVishwanatha Subbanna
1993b7b5619SAndrew Geissler# will write blocking errors to stdout
2003b7b5619SAndrew Geisslercheck_boot_block_errors ()
2013b7b5619SAndrew Geissler{
2023b7b5619SAndrew Geissler    # array of boot block objects
2033b7b5619SAndrew Geissler    blockArray=()
2043b7b5619SAndrew Geissler
2053b7b5619SAndrew Geissler    # Look for any objects under logging that implement the
2063b7b5619SAndrew Geissler    # xyz.openbmc_project.Logging.ErrorBlocksTransition
2073b7b5619SAndrew Geissler    subtree="$(busctl call xyz.openbmc_project.ObjectMapper \
2083b7b5619SAndrew Geissler               /xyz/openbmc_project/object_mapper \
2093b7b5619SAndrew Geissler               xyz.openbmc_project.ObjectMapper \
2103b7b5619SAndrew Geissler               GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \
2113b7b5619SAndrew Geissler               xyz.openbmc_project.Logging.ErrorBlocksTransition)"
2123b7b5619SAndrew Geissler
2133b7b5619SAndrew Geissler    # remove quotation marks
214*b2398200SPatrick Williams    # shellcheck disable=SC2001
215*b2398200SPatrick Williams    subtree="$(echo "$subtree" | sed 's/\"//g')"
2163b7b5619SAndrew Geissler
2173b7b5619SAndrew Geissler    for entry in $subtree; do
2183b7b5619SAndrew Geissler        if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then
219*b2398200SPatrick Williams            blockArray+=( "$entry" )
2203b7b5619SAndrew Geissler        fi
2213b7b5619SAndrew Geissler    done
2223b7b5619SAndrew Geissler
2233b7b5619SAndrew Geissler    # now find associated error log for each boot block error
2243b7b5619SAndrew Geissler    for berror in "${blockArray[@]}"; do
225*b2398200SPatrick Williams        assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \
2263b7b5619SAndrew Geissler                  org.freedesktop.DBus.Properties Get \
2273b7b5619SAndrew Geissler                  ss xyz.openbmc_project.Association.Definitions Associations)"
2283b7b5619SAndrew Geissler
2293b7b5619SAndrew Geissler        # remove quotation marks
230*b2398200SPatrick Williams        # shellcheck disable=SC2001
231*b2398200SPatrick Williams        assocs="$(echo "$assocs" | sed 's/\"//g')"
2323b7b5619SAndrew Geissler
2333b7b5619SAndrew Geissler        for entry in $assocs; do
2343b7b5619SAndrew Geissler            if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then
2353b7b5619SAndrew Geissler                echo "Blocking Error: $entry"
2363b7b5619SAndrew Geissler            fi
2373b7b5619SAndrew Geissler        done
2383b7b5619SAndrew Geissler    done
2393b7b5619SAndrew Geissler}
2403b7b5619SAndrew Geissler
241deb6bb45SAndrew Geissler# helper function to check for boot block errors and notify user
242deb6bb45SAndrew Geisslercheck_and_warn_boot_block()
243deb6bb45SAndrew Geissler{
244deb6bb45SAndrew Geissler    blockingErrors=$(check_boot_block_errors)
245*b2398200SPatrick Williams    if [ -n "$blockingErrors" ]; then
246deb6bb45SAndrew Geissler        echo !!!!!!!!!!
247deb6bb45SAndrew Geissler        echo "WARNING! System has blocking errors that will prevent boot"
248deb6bb45SAndrew Geissler        echo "$blockingErrors"
249deb6bb45SAndrew Geissler        echo !!!!!!!!!!
250deb6bb45SAndrew Geissler    fi
251deb6bb45SAndrew Geissler}
252deb6bb45SAndrew Geissler
253295ee4fbSAndrew Geissler# list all phosphor-logging entries
254295ee4fbSAndrew Geisslerlist_logs()
255295ee4fbSAndrew Geissler{
256295ee4fbSAndrew Geissler    # Look for any objects under logging that implement the
257295ee4fbSAndrew Geissler    # xyz.openbmc_project.Logging.Entry
258295ee4fbSAndrew Geissler    busctl -j call xyz.openbmc_project.ObjectMapper \
259295ee4fbSAndrew Geissler            /xyz/openbmc_project/object_mapper \
260295ee4fbSAndrew Geissler            xyz.openbmc_project.ObjectMapper \
261295ee4fbSAndrew Geissler            GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \
262295ee4fbSAndrew Geissler            xyz.openbmc_project.Logging.Entry
263295ee4fbSAndrew Geissler}
264295ee4fbSAndrew Geissler
265d8c63204SAndrew Geissler# display input log details
266d8c63204SAndrew Geisslershow_log()
267d8c63204SAndrew Geissler{
268d8c63204SAndrew Geissler    busctl -j call xyz.openbmc_project.Logging \
269*b2398200SPatrick Williams           "$1" \
270d8c63204SAndrew Geissler           org.freedesktop.DBus.Properties \
271d8c63204SAndrew Geissler           GetAll s xyz.openbmc_project.Logging.Entry
272d8c63204SAndrew Geissler}
273d8c63204SAndrew Geissler
27442f2898dSAndrew Geissler# delete all phosphor-logging entries
27542f2898dSAndrew Geisslerdelete_logs()
27642f2898dSAndrew Geissler{
27742f2898dSAndrew Geissler    busctl call xyz.openbmc_project.Logging \
27842f2898dSAndrew Geissler           /xyz/openbmc_project/logging \
27942f2898dSAndrew Geissler           xyz.openbmc_project.Collection.DeleteAll DeleteAll
28042f2898dSAndrew Geissler}
28142f2898dSAndrew Geissler
28279f697e0SAnthony Wilsonhandle_cmd ()
28379f697e0SAnthony Wilson{
28479f697e0SAnthony Wilson    case "$1" in
2853ae0a354SAnthony Wilson        chassisoff)
2863ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
2873ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2883ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
2893ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
2903ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
291acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.Off
292acf54d08SAnthony Wilson            G_QUERY="chassisstate"
293*b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2943ae0a354SAnthony Wilson            ;;
2953ae0a354SAnthony Wilson        chassison)
296deb6bb45SAndrew Geissler            check_and_warn_boot_block
2973ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
2983ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2993ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
3003ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
3013ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
302acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.On
303acf54d08SAnthony Wilson            G_QUERY="chassisstate"
304*b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
3053ae0a354SAnthony Wilson            ;;
3063ae0a354SAnthony Wilson        poweroff)
3073ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
3083ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3093ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
3103ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
3113ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
312acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Off
313acf54d08SAnthony Wilson            G_QUERY="hoststate"
314*b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
3153ae0a354SAnthony Wilson            ;;
3163ae0a354SAnthony Wilson        poweron)
317deb6bb45SAndrew Geissler            check_and_warn_boot_block
3183ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
3193ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3203ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
3213ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
3223ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
323acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Running
324acf54d08SAnthony Wilson            G_QUERY="hoststate"
325*b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
3263ae0a354SAnthony Wilson            ;;
32779f697e0SAnthony Wilson        bmcstate)
32879f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/bmc0
32979f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
33079f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.BMC
33179f697e0SAnthony Wilson            PROPERTY=CurrentBMCState
332*b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
33379f697e0SAnthony Wilson            ;;
33479f697e0SAnthony Wilson        chassisstate)
33579f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
33679f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
33779f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
33879f697e0SAnthony Wilson            PROPERTY=CurrentPowerState
339*b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
34079f697e0SAnthony Wilson            ;;
34179f697e0SAnthony Wilson        hoststate)
34279f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
34379f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
34479f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
34579f697e0SAnthony Wilson            PROPERTY=CurrentHostState
346*b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
34779f697e0SAnthony Wilson            ;;
34886cffd9cSAlexander Filippov        osstate)
34986cffd9cSAlexander Filippov            OBJECT=$STATE_OBJECT/host0
35086cffd9cSAlexander Filippov            SERVICE=$(mapper get-service $OBJECT)
35186cffd9cSAlexander Filippov            INTERFACE=$STATE_INTERFACE.OperatingSystem.Status
35286cffd9cSAlexander Filippov            PROPERTY=OperatingSystemState
353*b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
35486cffd9cSAlexander Filippov            ;;
35579f697e0SAnthony Wilson        state|status)
35686cffd9cSAlexander Filippov            for query in bmcstate chassisstate hoststate bootprogress osstate
35779f697e0SAnthony Wilson            do
35879f697e0SAnthony Wilson                handle_cmd $query
35979f697e0SAnthony Wilson            done
360deb6bb45SAndrew Geissler            check_and_warn_boot_block
36179f697e0SAnthony Wilson            ;;
36250c5f88dSAnthony Wilson        bootprogress)
36350c5f88dSAnthony Wilson            OBJECT=$STATE_OBJECT/host0
36450c5f88dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
36550c5f88dSAnthony Wilson            INTERFACE=$STATE_INTERFACE.Boot.Progress
36650c5f88dSAnthony Wilson            PROPERTY=BootProgress
367*b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
36850c5f88dSAnthony Wilson            ;;
3690f35983dSAnthony Wilson        power)
3700f35983dSAnthony Wilson            OBJECT=/org/openbmc/control/power0
3710f35983dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3720f35983dSAnthony Wilson            INTERFACE=org.openbmc.control.Power
3730f35983dSAnthony Wilson            for property in pgood state pgood_timeout
3740f35983dSAnthony Wilson            do
3750f35983dSAnthony Wilson                # get_property can potentially return several
3760f35983dSAnthony Wilson                # different formats of values, so we do the parsing outside
3770f35983dSAnthony Wilson                # of get_property depending on the query. These queries
3780f35983dSAnthony Wilson                # return 'i VALUE' formatted strings.
379*b2398200SPatrick Williams                STATE=$(get_property "$SERVICE" $OBJECT $INTERFACE $property \
3800f35983dSAnthony Wilson                    | sed 's/i[ ^I]*//')
381*b2398200SPatrick Williams                printf "%s = %s\n" $property "$STATE"
3820f35983dSAnthony Wilson            done
3830f35983dSAnthony Wilson            ;;
384189cf248SAnthony Wilson        chassiskill)
385189cf248SAnthony Wilson            /usr/libexec/chassiskill
386189cf248SAnthony Wilson            ;;
387a65d30d1SVishwanatha Subbanna        hostrebootoff)
3886d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
3896d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
3906d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
3916d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
3926d3a2c54SVishwanatha Subbanna            VALUE=false
393*b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
3946d3a2c54SVishwanatha Subbanna            ;;
3953191be88SAndrew Geissler        hostrebootoffonetime)
3963191be88SAndrew Geissler            OBJECT=$CONTROL_OBJECT/host0/auto_reboot/one_time
3973191be88SAndrew Geissler            SERVICE=$(mapper get-service $OBJECT)
3983191be88SAndrew Geissler            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
3993191be88SAndrew Geissler            PROPERTY=AutoReboot
4003191be88SAndrew Geissler            VALUE=false
401*b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
4023191be88SAndrew Geissler        ;;
403a65d30d1SVishwanatha Subbanna        hostrebooton)
4046d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
4056d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
4066d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
4076d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
4086d3a2c54SVishwanatha Subbanna            VALUE=true
409*b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
4106d3a2c54SVishwanatha Subbanna            ;;
411a65d30d1SVishwanatha Subbanna        bmcrebootoff)
412a65d30d1SVishwanatha Subbanna            disable_bmc_reboot
413a65d30d1SVishwanatha Subbanna            ;;
414a65d30d1SVishwanatha Subbanna        bmcrebooton)
415a65d30d1SVishwanatha Subbanna            enable_bmc_reboot
416a65d30d1SVishwanatha Subbanna            ;;
4177a787dd7SVishwanatha Subbanna        recoveryoff)
418a65d30d1SVishwanatha Subbanna            handle_cmd hostrebootoff
419a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebootoff
4207a787dd7SVishwanatha Subbanna            mask_systemd_target $HOST_TIMEOUT_TARGET
42184b3b29eSVishwanatha Subbanna            mask_systemd_target $HOST_CRASH_TARGET
4227a787dd7SVishwanatha Subbanna            ;;
4237a787dd7SVishwanatha Subbanna        recoveryon)
424a65d30d1SVishwanatha Subbanna            handle_cmd hostrebooton
425a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebooton
4267a787dd7SVishwanatha Subbanna            unmask_systemd_target $HOST_TIMEOUT_TARGET
42784b3b29eSVishwanatha Subbanna            unmask_systemd_target $HOST_CRASH_TARGET
4287a787dd7SVishwanatha Subbanna            ;;
4293b7b5619SAndrew Geissler        listbootblock)
4303b7b5619SAndrew Geissler            blockingErrors=$(check_boot_block_errors)
4313b7b5619SAndrew Geissler            if [ -z "$blockingErrors" ]; then
4323b7b5619SAndrew Geissler                echo "No blocking errors present"
4333b7b5619SAndrew Geissler            else
4343b7b5619SAndrew Geissler                echo "$blockingErrors"
4353b7b5619SAndrew Geissler            fi
4363b7b5619SAndrew Geissler            ;;
437295ee4fbSAndrew Geissler        listlogs)
438295ee4fbSAndrew Geissler            list_logs
439295ee4fbSAndrew Geissler            ;;
440d8c63204SAndrew Geissler        showlog)
441*b2398200SPatrick Williams            show_log "$2"
442d8c63204SAndrew Geissler            ;;
44342f2898dSAndrew Geissler        deletelogs)
44442f2898dSAndrew Geissler            delete_logs
44542f2898dSAndrew Geissler            ;;
44679f697e0SAnthony Wilson        *)
447ea87db40SAnthony Wilson            print_usage_err "Invalid command '$1'"
44879f697e0SAnthony Wilson            ;;
44979f697e0SAnthony Wilson    esac
45079f697e0SAnthony Wilson}
45179f697e0SAnthony Wilson
452d8779cd8SAndrew Geisslershiftcnt=0
453ea87db40SAnthony Wilsonfor arg in "$@"; do
454ea87db40SAnthony Wilson    case $arg in
455acf54d08SAnthony Wilson        -w|--wait)
456acf54d08SAnthony Wilson            G_WAIT=30
457d8779cd8SAndrew Geissler            shiftcnt=$((shiftcnt+1))
458acf54d08SAnthony Wilson            continue
459acf54d08SAnthony Wilson            ;;
460ea87db40SAnthony Wilson        -h|--help)
461ea87db40SAnthony Wilson            print_help
462ea87db40SAnthony Wilson            ;;
46360c3ac8cSAndrew Jeffery        -v|--verbose)
46460c3ac8cSAndrew Jeffery            G_VERBOSE=y
465d8779cd8SAndrew Geissler            shiftcnt=$((shiftcnt+1))
46660c3ac8cSAndrew Jeffery            ;;
467ea87db40SAnthony Wilson        -*)
468ea87db40SAnthony Wilson            print_usage_err "Unknown option: $arg"
469ea87db40SAnthony Wilson            ;;
470ea87db40SAnthony Wilson        *)
471acf54d08SAnthony Wilson            G_ORIG_CMD=$arg
472d8779cd8SAndrew Geissler            # shift out the optional parameters
473d8779cd8SAndrew Geissler            shift $shiftcnt
474d8c63204SAndrew Geissler            # pass all arguments to handle_cmd in case command takes additional
475d8c63204SAndrew Geissler            # parameters
476d8c63204SAndrew Geissler            handle_cmd "$@"
477ea87db40SAnthony Wilson            break
478ea87db40SAnthony Wilson            ;;
479ea87db40SAnthony Wilson    esac
480ea87db40SAnthony Wilsondone
481