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*3b7b5619SAndrew Geisslerbmcrebootoff, bmcrebooton, listbootblock"
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 ""
63*3b7b5619SAndrew Geissler    echo "obmcutil listbootblock Check for and list any errors blocking the boot"
64*3b7b5619SAndrew Geissler    echo "                       of the system"
65*3b7b5619SAndrew Geissler    echo ""
66f3f16fa9SAnthony Wilson    echo "optional arguments:"
67f3f16fa9SAnthony Wilson    echo "  -h, --help          show this help message and exit"
68acf54d08SAnthony Wilson    echo "  -w, --wait          block until state transition succeeds or fails"
6960c3ac8cSAndrew Jeffery    echo "  -v, --verbose       print the journal to stdout if --wait is supplied"
70f3f16fa9SAnthony Wilson    exit 0
71f3f16fa9SAnthony Wilson}
72f3f16fa9SAnthony Wilson
73acf54d08SAnthony Wilsonrun_timeout ()
74acf54d08SAnthony Wilson{
75acf54d08SAnthony Wilson    local timeout="$1"; shift
76acf54d08SAnthony Wilson    local cmd="$@"
7760c3ac8cSAndrew Jeffery    local verbose_child=
7860c3ac8cSAndrew Jeffery
792869a926SAndrew Jeffery    if [ -n "$G_VERBOSE" ]; then
8060c3ac8cSAndrew Jeffery        journalctl -f &
8160c3ac8cSAndrew Jeffery        verbose_child=$!
8260c3ac8cSAndrew Jeffery    fi
83acf54d08SAnthony Wilson
84acf54d08SAnthony Wilson    $cmd
85acf54d08SAnthony Wilson
86acf54d08SAnthony Wilson    # Run a background query for the transition to the expected state
87acf54d08SAnthony Wilson    # This will be killed if the transition doesn't succeed within
88acf54d08SAnthony Wilson    # a timeout period.
89acf54d08SAnthony Wilson    (
90acf54d08SAnthony Wilson        while ! grep -q $G_REQUESTED_STATE <<< $(handle_cmd $G_QUERY) ; do
91acf54d08SAnthony Wilson            sleep 1
92acf54d08SAnthony Wilson        done
93acf54d08SAnthony Wilson    ) &
9460c3ac8cSAndrew Jeffery    wait_child=$!
95acf54d08SAnthony Wilson
96acf54d08SAnthony Wilson    # Could be bad if process is killed before 'timeout' occurs if
97acf54d08SAnthony Wilson    # transition doesn't succeed.
98acf54d08SAnthony Wilson    trap -- "" SIGTERM
99acf54d08SAnthony Wilson
100acf54d08SAnthony Wilson    # Workaround for lack of 'timeout' command.
101acf54d08SAnthony Wilson    (
102acf54d08SAnthony Wilson        sleep $timeout
10360c3ac8cSAndrew Jeffery        kill $wait_child
104acf54d08SAnthony Wilson    ) > /dev/null 2>&1 &
105acf54d08SAnthony Wilson
10660c3ac8cSAndrew Jeffery    if ! wait $wait_child; then
107acf54d08SAnthony Wilson        echo "Unable to confirm '$G_ORIG_CMD' success" \
108acf54d08SAnthony Wilson        "within timeout period (${timeout}s)"
109acf54d08SAnthony Wilson    fi
11060c3ac8cSAndrew Jeffery
1118be70293SAndrew Jeffery    if [ -n "$verbose_child" ]; then
11260c3ac8cSAndrew Jeffery        kill $verbose_child
11360c3ac8cSAndrew Jeffery    fi
114acf54d08SAnthony Wilson}
115acf54d08SAnthony Wilson
116acf54d08SAnthony Wilsonrun_cmd ()
117acf54d08SAnthony Wilson{
118acf54d08SAnthony Wilson    local cmd="$@";
119acf54d08SAnthony Wilson
120acf54d08SAnthony Wilson    if [ -n "$G_WAIT" ]; then
121acf54d08SAnthony Wilson        run_timeout $G_WAIT "$cmd"
122acf54d08SAnthony Wilson    else
123acf54d08SAnthony Wilson        $cmd
124acf54d08SAnthony Wilson    fi
125acf54d08SAnthony Wilson}
126acf54d08SAnthony Wilson
1273ae0a354SAnthony Wilsonset_property ()
1283ae0a354SAnthony Wilson{
129acf54d08SAnthony Wilson    run_cmd busctl set-property "$@"
1303ae0a354SAnthony Wilson}
1313ae0a354SAnthony Wilson
13279f697e0SAnthony Wilsonget_property ()
13379f697e0SAnthony Wilson{
134acf54d08SAnthony Wilson    G_WAIT=""
135acf54d08SAnthony Wilson    run_cmd busctl get-property "$@"
13679f697e0SAnthony Wilson}
13779f697e0SAnthony Wilson
13879f697e0SAnthony Wilsonstate_query ()
13979f697e0SAnthony Wilson{
14079f697e0SAnthony Wilson    local state=$(get_property "$@" | cut -d '"' -f2)
14179f697e0SAnthony Wilson    printf "%-20s: %s\n" $4 $state
14279f697e0SAnthony Wilson}
14379f697e0SAnthony Wilson
144ea87db40SAnthony Wilsonprint_usage_err ()
145ea87db40SAnthony Wilson{
146ea87db40SAnthony Wilson    echo "ERROR: $1" >&2
147ea87db40SAnthony Wilson    echo "$USAGE"
148ea87db40SAnthony Wilson    exit 1
149ea87db40SAnthony Wilson}
150ea87db40SAnthony Wilson
1517a787dd7SVishwanatha Subbannamask_systemd_target ()
1527a787dd7SVishwanatha Subbanna{
1537a787dd7SVishwanatha Subbanna    target="$@"
1547a787dd7SVishwanatha Subbanna    systemctl mask $target
1557a787dd7SVishwanatha Subbanna}
1567a787dd7SVishwanatha Subbanna
1577a787dd7SVishwanatha Subbannaunmask_systemd_target ()
1587a787dd7SVishwanatha Subbanna{
1597a787dd7SVishwanatha Subbanna    target="$@"
1607a787dd7SVishwanatha Subbanna    systemctl unmask $target
1617a787dd7SVishwanatha Subbanna}
1627a787dd7SVishwanatha Subbanna
163a65d30d1SVishwanatha Subbannadisable_bmc_reboot ()
164a65d30d1SVishwanatha Subbanna{
165a65d30d1SVishwanatha Subbanna    dir="/run/systemd/system/"
166a65d30d1SVishwanatha Subbanna    file="reboot-guard.conf"
167a65d30d1SVishwanatha Subbanna    units=("reboot" "poweroff" "halt")
168a65d30d1SVishwanatha Subbanna
169a65d30d1SVishwanatha Subbanna    for unit in "${units[@]}"; do
170a65d30d1SVishwanatha Subbanna        mkdir -p ${dir}${unit}.target.d
171a65d30d1SVishwanatha Subbanna        echo -e "[Unit]\nRefuseManualStart=yes" >> ${dir}${unit}.target.d/${file}
172a65d30d1SVishwanatha Subbanna    done
173a65d30d1SVishwanatha Subbanna}
174a65d30d1SVishwanatha Subbanna
175a65d30d1SVishwanatha Subbannaenable_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
182a65d30d1SVishwanatha Subbanna        rm -rf ${dir}${unit}.target.d/${file}
183a65d30d1SVishwanatha Subbanna        rm -rf ${dir}${unit}.target.d
184a65d30d1SVishwanatha Subbanna    done
185a65d30d1SVishwanatha Subbanna}
186a65d30d1SVishwanatha Subbanna
187*3b7b5619SAndrew Geissler# will write blocking errors to stdout
188*3b7b5619SAndrew Geisslercheck_boot_block_errors ()
189*3b7b5619SAndrew Geissler{
190*3b7b5619SAndrew Geissler    # array of boot block objects
191*3b7b5619SAndrew Geissler    blockArray=()
192*3b7b5619SAndrew Geissler
193*3b7b5619SAndrew Geissler    # Look for any objects under logging that implement the
194*3b7b5619SAndrew Geissler    # xyz.openbmc_project.Logging.ErrorBlocksTransition
195*3b7b5619SAndrew Geissler    subtree="$(busctl call xyz.openbmc_project.ObjectMapper \
196*3b7b5619SAndrew Geissler               /xyz/openbmc_project/object_mapper \
197*3b7b5619SAndrew Geissler               xyz.openbmc_project.ObjectMapper \
198*3b7b5619SAndrew Geissler               GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \
199*3b7b5619SAndrew Geissler               xyz.openbmc_project.Logging.ErrorBlocksTransition)"
200*3b7b5619SAndrew Geissler
201*3b7b5619SAndrew Geissler    # remove quotation marks
202*3b7b5619SAndrew Geissler    subtree="$(echo $subtree | sed 's/\"//g')"
203*3b7b5619SAndrew Geissler
204*3b7b5619SAndrew Geissler    for entry in $subtree; do
205*3b7b5619SAndrew Geissler        if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then
206*3b7b5619SAndrew Geissler            blockArray+=( $entry )
207*3b7b5619SAndrew Geissler        fi
208*3b7b5619SAndrew Geissler    done
209*3b7b5619SAndrew Geissler
210*3b7b5619SAndrew Geissler    # now find associated error log for each boot block error
211*3b7b5619SAndrew Geissler    for berror in "${blockArray[@]}"; do
212*3b7b5619SAndrew Geissler        assocs="$(busctl call xyz.openbmc_project.Logging $berror \
213*3b7b5619SAndrew Geissler                  org.freedesktop.DBus.Properties Get \
214*3b7b5619SAndrew Geissler                  ss xyz.openbmc_project.Association.Definitions Associations)"
215*3b7b5619SAndrew Geissler
216*3b7b5619SAndrew Geissler        # remove quotation marks
217*3b7b5619SAndrew Geissler        assocs="$(echo $assocs | sed 's/\"//g')"
218*3b7b5619SAndrew Geissler
219*3b7b5619SAndrew Geissler        for entry in $assocs; do
220*3b7b5619SAndrew Geissler            if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then
221*3b7b5619SAndrew Geissler                echo "Blocking Error: $entry"
222*3b7b5619SAndrew Geissler            fi
223*3b7b5619SAndrew Geissler        done
224*3b7b5619SAndrew Geissler    done
225*3b7b5619SAndrew Geissler}
226*3b7b5619SAndrew Geissler
22779f697e0SAnthony Wilsonhandle_cmd ()
22879f697e0SAnthony Wilson{
22979f697e0SAnthony Wilson    case "$1" in
2303ae0a354SAnthony Wilson        chassisoff)
2313ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
2323ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2333ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
2343ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
2353ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
236acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.Off
237acf54d08SAnthony Wilson            G_QUERY="chassisstate"
2383ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2393ae0a354SAnthony Wilson            ;;
2403ae0a354SAnthony Wilson        chassison)
2413ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
2423ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2433ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
2443ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
2453ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
246acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.On
247acf54d08SAnthony Wilson            G_QUERY="chassisstate"
2483ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2493ae0a354SAnthony Wilson            ;;
2503ae0a354SAnthony Wilson        poweroff)
2513ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
2523ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2533ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
2543ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
2553ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
256acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Off
257acf54d08SAnthony Wilson            G_QUERY="hoststate"
2583ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2593ae0a354SAnthony Wilson            ;;
2603ae0a354SAnthony Wilson        poweron)
2613ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
2623ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
2633ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
2643ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
2653ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
266acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Running
267acf54d08SAnthony Wilson            G_QUERY="hoststate"
2683ae0a354SAnthony Wilson            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE
2693ae0a354SAnthony Wilson            ;;
27079f697e0SAnthony Wilson        bmcstate)
27179f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/bmc0
27279f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
27379f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.BMC
27479f697e0SAnthony Wilson            PROPERTY=CurrentBMCState
27579f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
27679f697e0SAnthony Wilson            ;;
27779f697e0SAnthony Wilson        chassisstate)
27879f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
27979f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
28079f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
28179f697e0SAnthony Wilson            PROPERTY=CurrentPowerState
28279f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
28379f697e0SAnthony Wilson            ;;
28479f697e0SAnthony Wilson        hoststate)
28579f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
28679f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
28779f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
28879f697e0SAnthony Wilson            PROPERTY=CurrentHostState
28979f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
29079f697e0SAnthony Wilson            ;;
29186cffd9cSAlexander Filippov        osstate)
29286cffd9cSAlexander Filippov            OBJECT=$STATE_OBJECT/host0
29386cffd9cSAlexander Filippov            SERVICE=$(mapper get-service $OBJECT)
29486cffd9cSAlexander Filippov            INTERFACE=$STATE_INTERFACE.OperatingSystem.Status
29586cffd9cSAlexander Filippov            PROPERTY=OperatingSystemState
29686cffd9cSAlexander Filippov            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
29786cffd9cSAlexander Filippov            ;;
29879f697e0SAnthony Wilson        state|status)
29986cffd9cSAlexander Filippov            for query in bmcstate chassisstate hoststate bootprogress osstate
30079f697e0SAnthony Wilson            do
30179f697e0SAnthony Wilson                handle_cmd $query
30279f697e0SAnthony Wilson            done
30379f697e0SAnthony Wilson            ;;
30450c5f88dSAnthony Wilson        bootprogress)
30550c5f88dSAnthony Wilson            OBJECT=$STATE_OBJECT/host0
30650c5f88dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
30750c5f88dSAnthony Wilson            INTERFACE=$STATE_INTERFACE.Boot.Progress
30850c5f88dSAnthony Wilson            PROPERTY=BootProgress
30950c5f88dSAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
31050c5f88dSAnthony Wilson            ;;
3110f35983dSAnthony Wilson        power)
3120f35983dSAnthony Wilson            OBJECT=/org/openbmc/control/power0
3130f35983dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3140f35983dSAnthony Wilson            INTERFACE=org.openbmc.control.Power
3150f35983dSAnthony Wilson            for property in pgood state pgood_timeout
3160f35983dSAnthony Wilson            do
3170f35983dSAnthony Wilson                # get_property can potentially return several
3180f35983dSAnthony Wilson                # different formats of values, so we do the parsing outside
3190f35983dSAnthony Wilson                # of get_property depending on the query. These queries
3200f35983dSAnthony Wilson                # return 'i VALUE' formatted strings.
3210f35983dSAnthony Wilson                STATE=$(get_property $SERVICE $OBJECT $INTERFACE $property \
3220f35983dSAnthony Wilson                    | sed 's/i[ ^I]*//')
3230f35983dSAnthony Wilson                printf "%s = %s\n" $property $STATE
3240f35983dSAnthony Wilson            done
3250f35983dSAnthony Wilson            ;;
326189cf248SAnthony Wilson        chassiskill)
327189cf248SAnthony Wilson            /usr/libexec/chassiskill
328189cf248SAnthony Wilson            ;;
329a65d30d1SVishwanatha Subbanna        hostrebootoff)
3306d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
3316d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
3326d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
3336d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
3346d3a2c54SVishwanatha Subbanna            VALUE=false
3356d3a2c54SVishwanatha Subbanna            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "b" $VALUE
3366d3a2c54SVishwanatha Subbanna            ;;
337a65d30d1SVishwanatha Subbanna        hostrebooton)
3386d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
3396d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
3406d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
3416d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
3426d3a2c54SVishwanatha Subbanna            VALUE=true
3436d3a2c54SVishwanatha Subbanna            set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "b" $VALUE
3446d3a2c54SVishwanatha Subbanna            ;;
345a65d30d1SVishwanatha Subbanna        bmcrebootoff)
346a65d30d1SVishwanatha Subbanna            disable_bmc_reboot
347a65d30d1SVishwanatha Subbanna            ;;
348a65d30d1SVishwanatha Subbanna        bmcrebooton)
349a65d30d1SVishwanatha Subbanna            enable_bmc_reboot
350a65d30d1SVishwanatha Subbanna            ;;
3517a787dd7SVishwanatha Subbanna        recoveryoff)
352a65d30d1SVishwanatha Subbanna            handle_cmd hostrebootoff
353a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebootoff
3547a787dd7SVishwanatha Subbanna            mask_systemd_target $HOST_TIMEOUT_TARGET
35584b3b29eSVishwanatha Subbanna            mask_systemd_target $HOST_CRASH_TARGET
3567a787dd7SVishwanatha Subbanna            ;;
3577a787dd7SVishwanatha Subbanna        recoveryon)
358a65d30d1SVishwanatha Subbanna            handle_cmd hostrebooton
359a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebooton
3607a787dd7SVishwanatha Subbanna            unmask_systemd_target $HOST_TIMEOUT_TARGET
36184b3b29eSVishwanatha Subbanna            unmask_systemd_target $HOST_CRASH_TARGET
3627a787dd7SVishwanatha Subbanna            ;;
363*3b7b5619SAndrew Geissler        listbootblock)
364*3b7b5619SAndrew Geissler            blockingErrors=$(check_boot_block_errors)
365*3b7b5619SAndrew Geissler            if [ -z "$blockingErrors" ]; then
366*3b7b5619SAndrew Geissler                echo "No blocking errors present"
367*3b7b5619SAndrew Geissler            else
368*3b7b5619SAndrew Geissler                echo "$blockingErrors"
369*3b7b5619SAndrew Geissler            fi
370*3b7b5619SAndrew Geissler            ;;
37179f697e0SAnthony Wilson        *)
372ea87db40SAnthony Wilson            print_usage_err "Invalid command '$1'"
37379f697e0SAnthony Wilson            ;;
37479f697e0SAnthony Wilson    esac
37579f697e0SAnthony Wilson}
37679f697e0SAnthony Wilson
377ea87db40SAnthony Wilsonfor arg in "$@"; do
378ea87db40SAnthony Wilson    case $arg in
379acf54d08SAnthony Wilson        -w|--wait)
380acf54d08SAnthony Wilson            G_WAIT=30
381acf54d08SAnthony Wilson            continue
382acf54d08SAnthony Wilson            ;;
383ea87db40SAnthony Wilson        -h|--help)
384ea87db40SAnthony Wilson            print_help
385ea87db40SAnthony Wilson            ;;
38660c3ac8cSAndrew Jeffery        -v|--verbose)
38760c3ac8cSAndrew Jeffery            G_VERBOSE=y
38860c3ac8cSAndrew Jeffery            ;;
389ea87db40SAnthony Wilson        -*)
390ea87db40SAnthony Wilson            print_usage_err "Unknown option: $arg"
391ea87db40SAnthony Wilson            ;;
392ea87db40SAnthony Wilson        *)
393acf54d08SAnthony Wilson            G_ORIG_CMD=$arg
394ea87db40SAnthony Wilson            handle_cmd $arg
395ea87db40SAnthony Wilson            break
396ea87db40SAnthony Wilson            ;;
397ea87db40SAnthony Wilson    esac
398ea87db40SAnthony Wilsondone
399