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*42f2898dSAndrew 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" 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 "" 66295ee4fbSAndrew Geissler echo "obmcutil listlogs List all phosphor-logging entries on the" 67295ee4fbSAndrew Geissler echo " system" 68295ee4fbSAndrew Geissler echo "" 69d8c63204SAndrew Geissler echo "obmcutil showlog <log> Display details of input log. Format of <log>" 70d8c63204SAndrew Geissler echo " should match listlogs output" 71d8c63204SAndrew Geissler echo "" 72*42f2898dSAndrew Geissler echo "obmcutil deletelogs Delete all phosphor-logging entries from" 73*42f2898dSAndrew Geissler echo " system" 74*42f2898dSAndrew Geissler echo "" 75f3f16fa9SAnthony Wilson echo "optional arguments:" 76f3f16fa9SAnthony Wilson echo " -h, --help show this help message and exit" 77acf54d08SAnthony Wilson echo " -w, --wait block until state transition succeeds or fails" 7860c3ac8cSAndrew Jeffery echo " -v, --verbose print the journal to stdout if --wait is supplied" 79f3f16fa9SAnthony Wilson exit 0 80f3f16fa9SAnthony Wilson} 81f3f16fa9SAnthony Wilson 82acf54d08SAnthony Wilsonrun_timeout () 83acf54d08SAnthony Wilson{ 84acf54d08SAnthony Wilson local timeout="$1"; shift 85acf54d08SAnthony Wilson local cmd="$@" 8660c3ac8cSAndrew Jeffery local verbose_child= 8760c3ac8cSAndrew Jeffery 882869a926SAndrew Jeffery if [ -n "$G_VERBOSE" ]; then 8960c3ac8cSAndrew Jeffery journalctl -f & 9060c3ac8cSAndrew Jeffery verbose_child=$! 9160c3ac8cSAndrew Jeffery fi 92acf54d08SAnthony Wilson 93acf54d08SAnthony Wilson $cmd 94acf54d08SAnthony Wilson 95acf54d08SAnthony Wilson # Run a background query for the transition to the expected state 96acf54d08SAnthony Wilson # This will be killed if the transition doesn't succeed within 97acf54d08SAnthony Wilson # a timeout period. 98acf54d08SAnthony Wilson ( 99acf54d08SAnthony Wilson while ! grep -q $G_REQUESTED_STATE <<< $(handle_cmd $G_QUERY) ; do 100acf54d08SAnthony Wilson sleep 1 101acf54d08SAnthony Wilson done 102acf54d08SAnthony Wilson ) & 10360c3ac8cSAndrew Jeffery wait_child=$! 104acf54d08SAnthony Wilson 105acf54d08SAnthony Wilson # Could be bad if process is killed before 'timeout' occurs if 106acf54d08SAnthony Wilson # transition doesn't succeed. 107acf54d08SAnthony Wilson trap -- "" SIGTERM 108acf54d08SAnthony Wilson 109acf54d08SAnthony Wilson # Workaround for lack of 'timeout' command. 110acf54d08SAnthony Wilson ( 111acf54d08SAnthony Wilson sleep $timeout 11260c3ac8cSAndrew Jeffery kill $wait_child 113acf54d08SAnthony Wilson ) > /dev/null 2>&1 & 114acf54d08SAnthony Wilson 11560c3ac8cSAndrew Jeffery if ! wait $wait_child; then 116acf54d08SAnthony Wilson echo "Unable to confirm '$G_ORIG_CMD' success" \ 117acf54d08SAnthony Wilson "within timeout period (${timeout}s)" 118acf54d08SAnthony Wilson fi 11960c3ac8cSAndrew Jeffery 1208be70293SAndrew Jeffery if [ -n "$verbose_child" ]; then 12160c3ac8cSAndrew Jeffery kill $verbose_child 12260c3ac8cSAndrew Jeffery fi 123acf54d08SAnthony Wilson} 124acf54d08SAnthony Wilson 125acf54d08SAnthony Wilsonrun_cmd () 126acf54d08SAnthony Wilson{ 127acf54d08SAnthony Wilson local cmd="$@"; 128acf54d08SAnthony Wilson 129acf54d08SAnthony Wilson if [ -n "$G_WAIT" ]; then 130acf54d08SAnthony Wilson run_timeout $G_WAIT "$cmd" 131acf54d08SAnthony Wilson else 132acf54d08SAnthony Wilson $cmd 133acf54d08SAnthony Wilson fi 134acf54d08SAnthony Wilson} 135acf54d08SAnthony Wilson 1363ae0a354SAnthony Wilsonset_property () 1373ae0a354SAnthony Wilson{ 138acf54d08SAnthony Wilson run_cmd busctl set-property "$@" 1393ae0a354SAnthony Wilson} 1403ae0a354SAnthony Wilson 14179f697e0SAnthony Wilsonget_property () 14279f697e0SAnthony Wilson{ 143acf54d08SAnthony Wilson G_WAIT="" 144acf54d08SAnthony Wilson run_cmd busctl get-property "$@" 14579f697e0SAnthony Wilson} 14679f697e0SAnthony Wilson 14779f697e0SAnthony Wilsonstate_query () 14879f697e0SAnthony Wilson{ 14979f697e0SAnthony Wilson local state=$(get_property "$@" | cut -d '"' -f2) 15079f697e0SAnthony Wilson printf "%-20s: %s\n" $4 $state 15179f697e0SAnthony Wilson} 15279f697e0SAnthony Wilson 153ea87db40SAnthony Wilsonprint_usage_err () 154ea87db40SAnthony Wilson{ 155ea87db40SAnthony Wilson echo "ERROR: $1" >&2 156ea87db40SAnthony Wilson echo "$USAGE" 157ea87db40SAnthony Wilson exit 1 158ea87db40SAnthony Wilson} 159ea87db40SAnthony Wilson 1607a787dd7SVishwanatha Subbannamask_systemd_target () 1617a787dd7SVishwanatha Subbanna{ 1627a787dd7SVishwanatha Subbanna target="$@" 1637a787dd7SVishwanatha Subbanna systemctl mask $target 1647a787dd7SVishwanatha Subbanna} 1657a787dd7SVishwanatha Subbanna 1667a787dd7SVishwanatha Subbannaunmask_systemd_target () 1677a787dd7SVishwanatha Subbanna{ 1687a787dd7SVishwanatha Subbanna target="$@" 1697a787dd7SVishwanatha Subbanna systemctl unmask $target 1707a787dd7SVishwanatha Subbanna} 1717a787dd7SVishwanatha Subbanna 172a65d30d1SVishwanatha Subbannadisable_bmc_reboot () 173a65d30d1SVishwanatha Subbanna{ 174a65d30d1SVishwanatha Subbanna dir="/run/systemd/system/" 175a65d30d1SVishwanatha Subbanna file="reboot-guard.conf" 176a65d30d1SVishwanatha Subbanna units=("reboot" "poweroff" "halt") 177a65d30d1SVishwanatha Subbanna 178a65d30d1SVishwanatha Subbanna for unit in "${units[@]}"; do 179a65d30d1SVishwanatha Subbanna mkdir -p ${dir}${unit}.target.d 180a65d30d1SVishwanatha Subbanna echo -e "[Unit]\nRefuseManualStart=yes" >> ${dir}${unit}.target.d/${file} 181a65d30d1SVishwanatha Subbanna done 182a65d30d1SVishwanatha Subbanna} 183a65d30d1SVishwanatha Subbanna 184a65d30d1SVishwanatha Subbannaenable_bmc_reboot () 185a65d30d1SVishwanatha Subbanna{ 186a65d30d1SVishwanatha Subbanna dir="/run/systemd/system/" 187a65d30d1SVishwanatha Subbanna file="reboot-guard.conf" 188a65d30d1SVishwanatha Subbanna units=("reboot" "poweroff" "halt") 189a65d30d1SVishwanatha Subbanna 190a65d30d1SVishwanatha Subbanna for unit in "${units[@]}"; do 191a65d30d1SVishwanatha Subbanna rm -rf ${dir}${unit}.target.d/${file} 192a65d30d1SVishwanatha Subbanna rm -rf ${dir}${unit}.target.d 193a65d30d1SVishwanatha Subbanna done 194a65d30d1SVishwanatha Subbanna} 195a65d30d1SVishwanatha Subbanna 1963b7b5619SAndrew Geissler# will write blocking errors to stdout 1973b7b5619SAndrew Geisslercheck_boot_block_errors () 1983b7b5619SAndrew Geissler{ 1993b7b5619SAndrew Geissler # array of boot block objects 2003b7b5619SAndrew Geissler blockArray=() 2013b7b5619SAndrew Geissler 2023b7b5619SAndrew Geissler # Look for any objects under logging that implement the 2033b7b5619SAndrew Geissler # xyz.openbmc_project.Logging.ErrorBlocksTransition 2043b7b5619SAndrew Geissler subtree="$(busctl call xyz.openbmc_project.ObjectMapper \ 2053b7b5619SAndrew Geissler /xyz/openbmc_project/object_mapper \ 2063b7b5619SAndrew Geissler xyz.openbmc_project.ObjectMapper \ 2073b7b5619SAndrew Geissler GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \ 2083b7b5619SAndrew Geissler xyz.openbmc_project.Logging.ErrorBlocksTransition)" 2093b7b5619SAndrew Geissler 2103b7b5619SAndrew Geissler # remove quotation marks 2113b7b5619SAndrew Geissler subtree="$(echo $subtree | sed 's/\"//g')" 2123b7b5619SAndrew Geissler 2133b7b5619SAndrew Geissler for entry in $subtree; do 2143b7b5619SAndrew Geissler if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then 2153b7b5619SAndrew Geissler blockArray+=( $entry ) 2163b7b5619SAndrew Geissler fi 2173b7b5619SAndrew Geissler done 2183b7b5619SAndrew Geissler 2193b7b5619SAndrew Geissler # now find associated error log for each boot block error 2203b7b5619SAndrew Geissler for berror in "${blockArray[@]}"; do 2213b7b5619SAndrew Geissler assocs="$(busctl call xyz.openbmc_project.Logging $berror \ 2223b7b5619SAndrew Geissler org.freedesktop.DBus.Properties Get \ 2233b7b5619SAndrew Geissler ss xyz.openbmc_project.Association.Definitions Associations)" 2243b7b5619SAndrew Geissler 2253b7b5619SAndrew Geissler # remove quotation marks 2263b7b5619SAndrew Geissler assocs="$(echo $assocs | sed 's/\"//g')" 2273b7b5619SAndrew Geissler 2283b7b5619SAndrew Geissler for entry in $assocs; do 2293b7b5619SAndrew Geissler if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then 2303b7b5619SAndrew Geissler echo "Blocking Error: $entry" 2313b7b5619SAndrew Geissler fi 2323b7b5619SAndrew Geissler done 2333b7b5619SAndrew Geissler done 2343b7b5619SAndrew Geissler} 2353b7b5619SAndrew Geissler 236deb6bb45SAndrew Geissler# helper function to check for boot block errors and notify user 237deb6bb45SAndrew Geisslercheck_and_warn_boot_block() 238deb6bb45SAndrew Geissler{ 239deb6bb45SAndrew Geissler blockingErrors=$(check_boot_block_errors) 240deb6bb45SAndrew Geissler if ! [ -z "$blockingErrors" ]; then 241deb6bb45SAndrew Geissler echo !!!!!!!!!! 242deb6bb45SAndrew Geissler echo "WARNING! System has blocking errors that will prevent boot" 243deb6bb45SAndrew Geissler echo "$blockingErrors" 244deb6bb45SAndrew Geissler echo !!!!!!!!!! 245deb6bb45SAndrew Geissler fi 246deb6bb45SAndrew Geissler} 247deb6bb45SAndrew Geissler 248295ee4fbSAndrew Geissler# list all phosphor-logging entries 249295ee4fbSAndrew Geisslerlist_logs() 250295ee4fbSAndrew Geissler{ 251295ee4fbSAndrew Geissler # Look for any objects under logging that implement the 252295ee4fbSAndrew Geissler # xyz.openbmc_project.Logging.Entry 253295ee4fbSAndrew Geissler busctl -j call xyz.openbmc_project.ObjectMapper \ 254295ee4fbSAndrew Geissler /xyz/openbmc_project/object_mapper \ 255295ee4fbSAndrew Geissler xyz.openbmc_project.ObjectMapper \ 256295ee4fbSAndrew Geissler GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \ 257295ee4fbSAndrew Geissler xyz.openbmc_project.Logging.Entry 258295ee4fbSAndrew Geissler} 259295ee4fbSAndrew Geissler 260d8c63204SAndrew Geissler# display input log details 261d8c63204SAndrew Geisslershow_log() 262d8c63204SAndrew Geissler{ 263d8c63204SAndrew Geissler busctl -j call xyz.openbmc_project.Logging \ 264d8c63204SAndrew Geissler $1 \ 265d8c63204SAndrew Geissler org.freedesktop.DBus.Properties \ 266d8c63204SAndrew Geissler GetAll s xyz.openbmc_project.Logging.Entry 267d8c63204SAndrew Geissler} 268d8c63204SAndrew Geissler 269*42f2898dSAndrew Geissler# delete all phosphor-logging entries 270*42f2898dSAndrew Geisslerdelete_logs() 271*42f2898dSAndrew Geissler{ 272*42f2898dSAndrew Geissler busctl call xyz.openbmc_project.Logging \ 273*42f2898dSAndrew Geissler /xyz/openbmc_project/logging \ 274*42f2898dSAndrew Geissler xyz.openbmc_project.Collection.DeleteAll DeleteAll 275*42f2898dSAndrew Geissler} 276*42f2898dSAndrew Geissler 27779f697e0SAnthony Wilsonhandle_cmd () 27879f697e0SAnthony Wilson{ 27979f697e0SAnthony Wilson case "$1" in 2803ae0a354SAnthony Wilson chassisoff) 2813ae0a354SAnthony Wilson OBJECT=$STATE_OBJECT/chassis0 2823ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 2833ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 2843ae0a354SAnthony Wilson PROPERTY=RequestedPowerTransition 2853ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.Off 286acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.PowerState.Off 287acf54d08SAnthony Wilson G_QUERY="chassisstate" 2883ae0a354SAnthony Wilson set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE 2893ae0a354SAnthony Wilson ;; 2903ae0a354SAnthony Wilson chassison) 291deb6bb45SAndrew Geissler check_and_warn_boot_block 2923ae0a354SAnthony Wilson OBJECT=$STATE_OBJECT/chassis0 2933ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 2943ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 2953ae0a354SAnthony Wilson PROPERTY=RequestedPowerTransition 2963ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.On 297acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.PowerState.On 298acf54d08SAnthony Wilson G_QUERY="chassisstate" 2993ae0a354SAnthony Wilson set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE 3003ae0a354SAnthony Wilson ;; 3013ae0a354SAnthony Wilson poweroff) 3023ae0a354SAnthony Wilson OBJECT=$STATE_OBJECT/host0 3033ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3043ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 3053ae0a354SAnthony Wilson PROPERTY=RequestedHostTransition 3063ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.Off 307acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.HostState.Off 308acf54d08SAnthony Wilson G_QUERY="hoststate" 3093ae0a354SAnthony Wilson set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE 3103ae0a354SAnthony Wilson ;; 3113ae0a354SAnthony Wilson poweron) 312deb6bb45SAndrew Geissler check_and_warn_boot_block 3133ae0a354SAnthony Wilson OBJECT=$STATE_OBJECT/host0 3143ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3153ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 3163ae0a354SAnthony Wilson PROPERTY=RequestedHostTransition 3173ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.On 318acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.HostState.Running 319acf54d08SAnthony Wilson G_QUERY="hoststate" 3203ae0a354SAnthony Wilson set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "s" $VALUE 3213ae0a354SAnthony Wilson ;; 32279f697e0SAnthony Wilson bmcstate) 32379f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/bmc0 32479f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 32579f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.BMC 32679f697e0SAnthony Wilson PROPERTY=CurrentBMCState 32779f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 32879f697e0SAnthony Wilson ;; 32979f697e0SAnthony Wilson chassisstate) 33079f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/chassis0 33179f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 33279f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 33379f697e0SAnthony Wilson PROPERTY=CurrentPowerState 33479f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 33579f697e0SAnthony Wilson ;; 33679f697e0SAnthony Wilson hoststate) 33779f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/host0 33879f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 33979f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 34079f697e0SAnthony Wilson PROPERTY=CurrentHostState 34179f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 34279f697e0SAnthony Wilson ;; 34386cffd9cSAlexander Filippov osstate) 34486cffd9cSAlexander Filippov OBJECT=$STATE_OBJECT/host0 34586cffd9cSAlexander Filippov SERVICE=$(mapper get-service $OBJECT) 34686cffd9cSAlexander Filippov INTERFACE=$STATE_INTERFACE.OperatingSystem.Status 34786cffd9cSAlexander Filippov PROPERTY=OperatingSystemState 34886cffd9cSAlexander Filippov state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 34986cffd9cSAlexander Filippov ;; 35079f697e0SAnthony Wilson state|status) 35186cffd9cSAlexander Filippov for query in bmcstate chassisstate hoststate bootprogress osstate 35279f697e0SAnthony Wilson do 35379f697e0SAnthony Wilson handle_cmd $query 35479f697e0SAnthony Wilson done 355deb6bb45SAndrew Geissler check_and_warn_boot_block 35679f697e0SAnthony Wilson ;; 35750c5f88dSAnthony Wilson bootprogress) 35850c5f88dSAnthony Wilson OBJECT=$STATE_OBJECT/host0 35950c5f88dSAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 36050c5f88dSAnthony Wilson INTERFACE=$STATE_INTERFACE.Boot.Progress 36150c5f88dSAnthony Wilson PROPERTY=BootProgress 36250c5f88dSAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 36350c5f88dSAnthony Wilson ;; 3640f35983dSAnthony Wilson power) 3650f35983dSAnthony Wilson OBJECT=/org/openbmc/control/power0 3660f35983dSAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3670f35983dSAnthony Wilson INTERFACE=org.openbmc.control.Power 3680f35983dSAnthony Wilson for property in pgood state pgood_timeout 3690f35983dSAnthony Wilson do 3700f35983dSAnthony Wilson # get_property can potentially return several 3710f35983dSAnthony Wilson # different formats of values, so we do the parsing outside 3720f35983dSAnthony Wilson # of get_property depending on the query. These queries 3730f35983dSAnthony Wilson # return 'i VALUE' formatted strings. 3740f35983dSAnthony Wilson STATE=$(get_property $SERVICE $OBJECT $INTERFACE $property \ 3750f35983dSAnthony Wilson | sed 's/i[ ^I]*//') 3760f35983dSAnthony Wilson printf "%s = %s\n" $property $STATE 3770f35983dSAnthony Wilson done 3780f35983dSAnthony Wilson ;; 379189cf248SAnthony Wilson chassiskill) 380189cf248SAnthony Wilson /usr/libexec/chassiskill 381189cf248SAnthony Wilson ;; 382a65d30d1SVishwanatha Subbanna hostrebootoff) 3836d3a2c54SVishwanatha Subbanna OBJECT=$CONTROL_OBJECT/host0/auto_reboot 3846d3a2c54SVishwanatha Subbanna SERVICE=$(mapper get-service $OBJECT) 3856d3a2c54SVishwanatha Subbanna INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy 3866d3a2c54SVishwanatha Subbanna PROPERTY=AutoReboot 3876d3a2c54SVishwanatha Subbanna VALUE=false 3886d3a2c54SVishwanatha Subbanna set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "b" $VALUE 3896d3a2c54SVishwanatha Subbanna ;; 390a65d30d1SVishwanatha Subbanna hostrebooton) 3916d3a2c54SVishwanatha Subbanna OBJECT=$CONTROL_OBJECT/host0/auto_reboot 3926d3a2c54SVishwanatha Subbanna SERVICE=$(mapper get-service $OBJECT) 3936d3a2c54SVishwanatha Subbanna INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy 3946d3a2c54SVishwanatha Subbanna PROPERTY=AutoReboot 3956d3a2c54SVishwanatha Subbanna VALUE=true 3966d3a2c54SVishwanatha Subbanna set_property $SERVICE $OBJECT $INTERFACE $PROPERTY "b" $VALUE 3976d3a2c54SVishwanatha Subbanna ;; 398a65d30d1SVishwanatha Subbanna bmcrebootoff) 399a65d30d1SVishwanatha Subbanna disable_bmc_reboot 400a65d30d1SVishwanatha Subbanna ;; 401a65d30d1SVishwanatha Subbanna bmcrebooton) 402a65d30d1SVishwanatha Subbanna enable_bmc_reboot 403a65d30d1SVishwanatha Subbanna ;; 4047a787dd7SVishwanatha Subbanna recoveryoff) 405a65d30d1SVishwanatha Subbanna handle_cmd hostrebootoff 406a65d30d1SVishwanatha Subbanna handle_cmd bmcrebootoff 4077a787dd7SVishwanatha Subbanna mask_systemd_target $HOST_TIMEOUT_TARGET 40884b3b29eSVishwanatha Subbanna mask_systemd_target $HOST_CRASH_TARGET 4097a787dd7SVishwanatha Subbanna ;; 4107a787dd7SVishwanatha Subbanna recoveryon) 411a65d30d1SVishwanatha Subbanna handle_cmd hostrebooton 412a65d30d1SVishwanatha Subbanna handle_cmd bmcrebooton 4137a787dd7SVishwanatha Subbanna unmask_systemd_target $HOST_TIMEOUT_TARGET 41484b3b29eSVishwanatha Subbanna unmask_systemd_target $HOST_CRASH_TARGET 4157a787dd7SVishwanatha Subbanna ;; 4163b7b5619SAndrew Geissler listbootblock) 4173b7b5619SAndrew Geissler blockingErrors=$(check_boot_block_errors) 4183b7b5619SAndrew Geissler if [ -z "$blockingErrors" ]; then 4193b7b5619SAndrew Geissler echo "No blocking errors present" 4203b7b5619SAndrew Geissler else 4213b7b5619SAndrew Geissler echo "$blockingErrors" 4223b7b5619SAndrew Geissler fi 4233b7b5619SAndrew Geissler ;; 424295ee4fbSAndrew Geissler listlogs) 425295ee4fbSAndrew Geissler list_logs 426295ee4fbSAndrew Geissler ;; 427d8c63204SAndrew Geissler showlog) 428d8c63204SAndrew Geissler show_log $2 429d8c63204SAndrew Geissler ;; 430*42f2898dSAndrew Geissler deletelogs) 431*42f2898dSAndrew Geissler delete_logs 432*42f2898dSAndrew Geissler ;; 43379f697e0SAnthony Wilson *) 434ea87db40SAnthony Wilson print_usage_err "Invalid command '$1'" 43579f697e0SAnthony Wilson ;; 43679f697e0SAnthony Wilson esac 43779f697e0SAnthony Wilson} 43879f697e0SAnthony Wilson 439ea87db40SAnthony Wilsonfor arg in "$@"; do 440ea87db40SAnthony Wilson case $arg in 441acf54d08SAnthony Wilson -w|--wait) 442acf54d08SAnthony Wilson G_WAIT=30 443acf54d08SAnthony Wilson continue 444acf54d08SAnthony Wilson ;; 445ea87db40SAnthony Wilson -h|--help) 446ea87db40SAnthony Wilson print_help 447ea87db40SAnthony Wilson ;; 44860c3ac8cSAndrew Jeffery -v|--verbose) 44960c3ac8cSAndrew Jeffery G_VERBOSE=y 45060c3ac8cSAndrew Jeffery ;; 451ea87db40SAnthony Wilson -*) 452ea87db40SAnthony Wilson print_usage_err "Unknown option: $arg" 453ea87db40SAnthony Wilson ;; 454ea87db40SAnthony Wilson *) 455acf54d08SAnthony Wilson G_ORIG_CMD=$arg 456d8c63204SAndrew Geissler # pass all arguments to handle_cmd in case command takes additional 457d8c63204SAndrew Geissler # parameters 458d8c63204SAndrew Geissler handle_cmd "$@" 459ea87db40SAnthony Wilson break 460ea87db40SAnthony Wilson ;; 461ea87db40SAnthony Wilson esac 462ea87db40SAnthony Wilsondone 463