1b2398200SPatrick 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,\ 7ad1afe58SAndrew Geisslerbmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs, stopofftargets" 80f35983dSAnthony Wilson 90e044c48SPotin LaiUSAGE="Usage: obmcutil [-h] [--wait] [--verbose] [--id=<INSTANCE_ID>] 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= 410e044c48SPotin Lai# Instance id, default 0 420e044c48SPotin LaiG_INSTANCE_ID="0" 43acf54d08SAnthony Wilson 44*d182bff5SPatrick Williamsfunction print_help() 45f3f16fa9SAnthony Wilson{ 46f3f16fa9SAnthony Wilson echo "$USAGE" 47f3f16fa9SAnthony Wilson echo "" 48f3f16fa9SAnthony Wilson echo "positional arguments:" 490f35983dSAnthony Wilson echo " {$OPTS}" 50f3f16fa9SAnthony Wilson echo "" 516d3a2c54SVishwanatha Subbanna echo "Examples:" 526d3a2c54SVishwanatha Subbanna echo "" 53a65d30d1SVishwanatha Subbanna echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state" 543191be88SAndrew Geissler echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from" 553191be88SAndrew Geissler echo " Quiesce state for a single boot" 56a65d30d1SVishwanatha Subbanna echo "obmcutil hostrebooton Enable auto reboot of Host from Quiesce state" 57a65d30d1SVishwanatha Subbanna echo "" 58a65d30d1SVishwanatha Subbanna echo "obmcutil bmcrebootoff Disable reboot of BMC" 59a65d30d1SVishwanatha Subbanna echo "obmcutil bmcrebooton Enable reboot of BMC" 606d3a2c54SVishwanatha Subbanna echo "" 6184b3b29eSVishwanatha Subbanna echo "obmcutil recoveryoff Disable handling boot watchdog timeout and host crash" 62a65d30d1SVishwanatha Subbanna echo " Also, disable BMC and Host auto reboots" 63a65d30d1SVishwanatha Subbanna echo "" 6484b3b29eSVishwanatha Subbanna echo "obmcutil recoveryon Enable handling boot watchdog timeout and host crash" 65a65d30d1SVishwanatha Subbanna echo " Also, enable BMC and Host auto reboots" 667a787dd7SVishwanatha Subbanna echo "" 673b7b5619SAndrew Geissler echo "obmcutil listbootblock Check for and list any errors blocking the boot" 683b7b5619SAndrew Geissler echo " of the system" 693b7b5619SAndrew Geissler echo "" 70295ee4fbSAndrew Geissler echo "obmcutil listlogs List all phosphor-logging entries on the" 71295ee4fbSAndrew Geissler echo " system" 72295ee4fbSAndrew Geissler echo "" 73d8c63204SAndrew Geissler echo "obmcutil showlog <log> Display details of input log. Format of <log>" 74d8c63204SAndrew Geissler echo " should match listlogs output" 75d8c63204SAndrew Geissler echo "" 7642f2898dSAndrew Geissler echo "obmcutil deletelogs Delete all phosphor-logging entries from" 7742f2898dSAndrew Geissler echo " system" 78ad1afe58SAndrew Geissler echo "obmcutil stopofftargets Manually stop all obmc targets in power off" 79ad1afe58SAndrew Geissler echo " path" 8042f2898dSAndrew Geissler echo "" 81d8779cd8SAndrew Geissler echo "optional arguments (must precede the positional options above):" 82f3f16fa9SAnthony Wilson echo " -h, --help show this help message and exit" 83acf54d08SAnthony Wilson echo " -w, --wait block until state transition succeeds or fails" 8460c3ac8cSAndrew Jeffery echo " -v, --verbose print the journal to stdout if --wait is supplied" 850e044c48SPotin Lai echo " -i, -id instance id, default 0" 86f3f16fa9SAnthony Wilson exit 0 87f3f16fa9SAnthony Wilson} 88f3f16fa9SAnthony Wilson 89*d182bff5SPatrick Williamsfunction run_timeout() 90acf54d08SAnthony Wilson{ 91acf54d08SAnthony Wilson local timeout="$1"; shift 92b2398200SPatrick Williams local cmd="$*" 9360c3ac8cSAndrew Jeffery local verbose_child= 9460c3ac8cSAndrew Jeffery 952869a926SAndrew Jeffery if [ -n "$G_VERBOSE" ]; then 9660c3ac8cSAndrew Jeffery journalctl -f & 9760c3ac8cSAndrew Jeffery verbose_child=$! 9860c3ac8cSAndrew Jeffery fi 99acf54d08SAnthony Wilson 100acf54d08SAnthony Wilson $cmd 101acf54d08SAnthony Wilson 102acf54d08SAnthony Wilson # Run a background query for the transition to the expected state 103acf54d08SAnthony Wilson # This will be killed if the transition doesn't succeed within 104acf54d08SAnthony Wilson # a timeout period. 105acf54d08SAnthony Wilson ( 106b2398200SPatrick Williams while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do 107acf54d08SAnthony Wilson sleep 1 108acf54d08SAnthony Wilson done 109acf54d08SAnthony Wilson ) & 11060c3ac8cSAndrew Jeffery wait_child=$! 111acf54d08SAnthony Wilson 112acf54d08SAnthony Wilson # Could be bad if process is killed before 'timeout' occurs if 113acf54d08SAnthony Wilson # transition doesn't succeed. 114acf54d08SAnthony Wilson trap -- "" SIGTERM 115acf54d08SAnthony Wilson 116acf54d08SAnthony Wilson # Workaround for lack of 'timeout' command. 117acf54d08SAnthony Wilson ( 118b2398200SPatrick Williams sleep "$timeout" 11960c3ac8cSAndrew Jeffery kill $wait_child 120acf54d08SAnthony Wilson ) > /dev/null 2>&1 & 121acf54d08SAnthony Wilson 12260c3ac8cSAndrew Jeffery if ! wait $wait_child; then 123acf54d08SAnthony Wilson echo "Unable to confirm '$G_ORIG_CMD' success" \ 124acf54d08SAnthony Wilson "within timeout period (${timeout}s)" 125acf54d08SAnthony Wilson fi 12660c3ac8cSAndrew Jeffery 1278be70293SAndrew Jeffery if [ -n "$verbose_child" ]; then 12860c3ac8cSAndrew Jeffery kill $verbose_child 12960c3ac8cSAndrew Jeffery fi 130acf54d08SAnthony Wilson} 131acf54d08SAnthony Wilson 132*d182bff5SPatrick Williamsfunction run_cmd() 133acf54d08SAnthony Wilson{ 134b2398200SPatrick Williams local cmd="$*"; 135acf54d08SAnthony Wilson 136acf54d08SAnthony Wilson if [ -n "$G_WAIT" ]; then 137b2398200SPatrick Williams run_timeout "$G_WAIT" "$cmd" 138acf54d08SAnthony Wilson else 139acf54d08SAnthony Wilson $cmd 140acf54d08SAnthony Wilson fi 141acf54d08SAnthony Wilson} 142acf54d08SAnthony Wilson 143*d182bff5SPatrick Williamsfunction set_property() 1443ae0a354SAnthony Wilson{ 145acf54d08SAnthony Wilson run_cmd busctl set-property "$@" 1463ae0a354SAnthony Wilson} 1473ae0a354SAnthony Wilson 148*d182bff5SPatrick Williamsfunction get_property() 14979f697e0SAnthony Wilson{ 150acf54d08SAnthony Wilson G_WAIT="" 151acf54d08SAnthony Wilson run_cmd busctl get-property "$@" 15279f697e0SAnthony Wilson} 15379f697e0SAnthony Wilson 154*d182bff5SPatrick Williamsfunction state_query() 15579f697e0SAnthony Wilson{ 156b2398200SPatrick Williams local state 157b2398200SPatrick Williams state=$(get_property "$@" | cut -d '"' -f2) 158b2398200SPatrick Williams printf "%-20s: %s\n" "$4" "$state" 15979f697e0SAnthony Wilson} 16079f697e0SAnthony Wilson 161*d182bff5SPatrick Williamsfunction print_usage_err() 162ea87db40SAnthony Wilson{ 163ea87db40SAnthony Wilson echo "ERROR: $1" >&2 164ea87db40SAnthony Wilson echo "$USAGE" 165ea87db40SAnthony Wilson exit 1 166ea87db40SAnthony Wilson} 167ea87db40SAnthony Wilson 168*d182bff5SPatrick Williamsfunction mask_systemd_target() 1697a787dd7SVishwanatha Subbanna{ 170b2398200SPatrick Williams target="$*" 171b2398200SPatrick Williams systemctl mask "$target" 1727a787dd7SVishwanatha Subbanna} 1737a787dd7SVishwanatha Subbanna 174*d182bff5SPatrick Williamsfunction unmask_systemd_target() 1757a787dd7SVishwanatha Subbanna{ 176b2398200SPatrick Williams target="$*" 177b2398200SPatrick Williams systemctl unmask "$target" 1787a787dd7SVishwanatha Subbanna} 1797a787dd7SVishwanatha Subbanna 180*d182bff5SPatrick Williamsfunction disable_bmc_reboot() 181a65d30d1SVishwanatha Subbanna{ 182a65d30d1SVishwanatha Subbanna dir="/run/systemd/system/" 183a65d30d1SVishwanatha Subbanna file="reboot-guard.conf" 184a65d30d1SVishwanatha Subbanna units=("reboot" "poweroff" "halt") 185a65d30d1SVishwanatha Subbanna 186a65d30d1SVishwanatha Subbanna for unit in "${units[@]}"; do 187b2398200SPatrick Williams mkdir -p "${dir}${unit}.target.d" 188b2398200SPatrick Williams echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}" 189a65d30d1SVishwanatha Subbanna done 190a65d30d1SVishwanatha Subbanna} 191a65d30d1SVishwanatha Subbanna 192*d182bff5SPatrick Williamsfunction enable_bmc_reboot() 193a65d30d1SVishwanatha Subbanna{ 194a65d30d1SVishwanatha Subbanna dir="/run/systemd/system/" 195a65d30d1SVishwanatha Subbanna file="reboot-guard.conf" 196a65d30d1SVishwanatha Subbanna units=("reboot" "poweroff" "halt") 197a65d30d1SVishwanatha Subbanna 198a65d30d1SVishwanatha Subbanna for unit in "${units[@]}"; do 199b2398200SPatrick Williams rm -rf "${dir}${unit}.target.d/${file}" 200b2398200SPatrick Williams rm -rf "${dir}${unit}.target.d" 201a65d30d1SVishwanatha Subbanna done 202a65d30d1SVishwanatha Subbanna} 203a65d30d1SVishwanatha Subbanna 2043b7b5619SAndrew Geissler# will write blocking errors to stdout 205*d182bff5SPatrick Williamsfunction check_boot_block_errors() 2063b7b5619SAndrew Geissler{ 2073b7b5619SAndrew Geissler # array of boot block objects 2083b7b5619SAndrew Geissler blockArray=() 2093b7b5619SAndrew Geissler 2103b7b5619SAndrew Geissler # Look for any objects under logging that implement the 2113b7b5619SAndrew Geissler # xyz.openbmc_project.Logging.ErrorBlocksTransition 2123b7b5619SAndrew Geissler subtree="$(busctl call xyz.openbmc_project.ObjectMapper \ 2133b7b5619SAndrew Geissler /xyz/openbmc_project/object_mapper \ 2143b7b5619SAndrew Geissler xyz.openbmc_project.ObjectMapper \ 2153b7b5619SAndrew Geissler GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \ 2163b7b5619SAndrew Geissler xyz.openbmc_project.Logging.ErrorBlocksTransition)" 2173b7b5619SAndrew Geissler 2183b7b5619SAndrew Geissler # remove quotation marks 219b2398200SPatrick Williams # shellcheck disable=SC2001 220b2398200SPatrick Williams subtree="$(echo "$subtree" | sed 's/\"//g')" 2213b7b5619SAndrew Geissler 2223b7b5619SAndrew Geissler for entry in $subtree; do 2233b7b5619SAndrew Geissler if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then 224b2398200SPatrick Williams blockArray+=( "$entry" ) 2253b7b5619SAndrew Geissler fi 2263b7b5619SAndrew Geissler done 2273b7b5619SAndrew Geissler 2283b7b5619SAndrew Geissler # now find associated error log for each boot block error 2293b7b5619SAndrew Geissler for berror in "${blockArray[@]}"; do 230b2398200SPatrick Williams assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \ 2313b7b5619SAndrew Geissler org.freedesktop.DBus.Properties Get \ 2323b7b5619SAndrew Geissler ss xyz.openbmc_project.Association.Definitions Associations)" 2333b7b5619SAndrew Geissler 2343b7b5619SAndrew Geissler # remove quotation marks 235b2398200SPatrick Williams # shellcheck disable=SC2001 236b2398200SPatrick Williams assocs="$(echo "$assocs" | sed 's/\"//g')" 2373b7b5619SAndrew Geissler 2383b7b5619SAndrew Geissler for entry in $assocs; do 2393b7b5619SAndrew Geissler if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then 2403b7b5619SAndrew Geissler echo "Blocking Error: $entry" 2413b7b5619SAndrew Geissler fi 2423b7b5619SAndrew Geissler done 2433b7b5619SAndrew Geissler done 2443b7b5619SAndrew Geissler} 2453b7b5619SAndrew Geissler 246deb6bb45SAndrew Geissler# helper function to check for boot block errors and notify user 247*d182bff5SPatrick Williamsfunction check_and_warn_boot_block() 248deb6bb45SAndrew Geissler{ 249deb6bb45SAndrew Geissler blockingErrors=$(check_boot_block_errors) 250b2398200SPatrick Williams if [ -n "$blockingErrors" ]; then 251deb6bb45SAndrew Geissler echo !!!!!!!!!! 252deb6bb45SAndrew Geissler echo "WARNING! System has blocking errors that will prevent boot" 253deb6bb45SAndrew Geissler echo "$blockingErrors" 254deb6bb45SAndrew Geissler echo !!!!!!!!!! 255deb6bb45SAndrew Geissler fi 256deb6bb45SAndrew Geissler} 257deb6bb45SAndrew Geissler 258295ee4fbSAndrew Geissler# list all phosphor-logging entries 259*d182bff5SPatrick Williamsfunction list_logs() 260295ee4fbSAndrew Geissler{ 261295ee4fbSAndrew Geissler # Look for any objects under logging that implement the 262295ee4fbSAndrew Geissler # xyz.openbmc_project.Logging.Entry 263295ee4fbSAndrew Geissler busctl -j call xyz.openbmc_project.ObjectMapper \ 264295ee4fbSAndrew Geissler /xyz/openbmc_project/object_mapper \ 265295ee4fbSAndrew Geissler xyz.openbmc_project.ObjectMapper \ 266295ee4fbSAndrew Geissler GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \ 267295ee4fbSAndrew Geissler xyz.openbmc_project.Logging.Entry 268295ee4fbSAndrew Geissler} 269295ee4fbSAndrew Geissler 270d8c63204SAndrew Geissler# display input log details 271*d182bff5SPatrick Williamsfunction show_log() 272d8c63204SAndrew Geissler{ 273d8c63204SAndrew Geissler busctl -j call xyz.openbmc_project.Logging \ 274b2398200SPatrick Williams "$1" \ 275d8c63204SAndrew Geissler org.freedesktop.DBus.Properties \ 276d8c63204SAndrew Geissler GetAll s xyz.openbmc_project.Logging.Entry 277d8c63204SAndrew Geissler} 278d8c63204SAndrew Geissler 27942f2898dSAndrew Geissler# delete all phosphor-logging entries 280*d182bff5SPatrick Williamsfunction delete_logs() 28142f2898dSAndrew Geissler{ 28242f2898dSAndrew Geissler busctl call xyz.openbmc_project.Logging \ 28342f2898dSAndrew Geissler /xyz/openbmc_project/logging \ 28442f2898dSAndrew Geissler xyz.openbmc_project.Collection.DeleteAll DeleteAll 28542f2898dSAndrew Geissler} 28642f2898dSAndrew Geissler 287ad1afe58SAndrew Geissler# stop all targets associated with powering off a system 288*d182bff5SPatrick Williamsfunction stop_off_targets() 289ad1afe58SAndrew Geissler{ 290ad1afe58SAndrew Geissler systemctl stop \ 291ad1afe58SAndrew Geissler obmc-chassis-powered-off@0.target \ 292ad1afe58SAndrew Geissler obmc-host-stop-pre@0.target \ 293ad1afe58SAndrew Geissler obmc-host-stopped@0.target \ 294ad1afe58SAndrew Geissler obmc-host-stopping@0.target \ 295ad1afe58SAndrew Geissler obmc-power-off@0.target \ 296ad1afe58SAndrew Geissler obmc-power-stop-pre@0.target \ 297ad1afe58SAndrew Geissler obmc-power-stop@0.target 298ad1afe58SAndrew Geissler} 299ad1afe58SAndrew Geissler 300*d182bff5SPatrick Williamsfunction handle_cmd() 30179f697e0SAnthony Wilson{ 30279f697e0SAnthony Wilson case "$1" in 3033ae0a354SAnthony Wilson chassisoff) 3040e044c48SPotin Lai OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID 3053ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3063ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 3073ae0a354SAnthony Wilson PROPERTY=RequestedPowerTransition 3083ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.Off 309acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.PowerState.Off 310acf54d08SAnthony Wilson G_QUERY="chassisstate" 311b2398200SPatrick Williams set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE 3123ae0a354SAnthony Wilson ;; 3133ae0a354SAnthony Wilson chassison) 314deb6bb45SAndrew Geissler check_and_warn_boot_block 3150e044c48SPotin Lai OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID 3163ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3173ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 3183ae0a354SAnthony Wilson PROPERTY=RequestedPowerTransition 3193ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.On 320acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.PowerState.On 321acf54d08SAnthony Wilson G_QUERY="chassisstate" 322b2398200SPatrick Williams set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE 3233ae0a354SAnthony Wilson ;; 3243ae0a354SAnthony Wilson poweroff) 3250e044c48SPotin Lai OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID 3263ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3273ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 3283ae0a354SAnthony Wilson PROPERTY=RequestedHostTransition 3293ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.Off 330acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.HostState.Off 331acf54d08SAnthony Wilson G_QUERY="hoststate" 332b2398200SPatrick Williams set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE 3333ae0a354SAnthony Wilson ;; 3343ae0a354SAnthony Wilson poweron) 335deb6bb45SAndrew Geissler check_and_warn_boot_block 3360e044c48SPotin Lai OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID 3373ae0a354SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3383ae0a354SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 3393ae0a354SAnthony Wilson PROPERTY=RequestedHostTransition 3403ae0a354SAnthony Wilson VALUE=$INTERFACE.Transition.On 341acf54d08SAnthony Wilson G_REQUESTED_STATE=$INTERFACE.HostState.Running 342acf54d08SAnthony Wilson G_QUERY="hoststate" 343b2398200SPatrick Williams set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE 3443ae0a354SAnthony Wilson ;; 34579f697e0SAnthony Wilson bmcstate) 34679f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/bmc0 34779f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 34879f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.BMC 34979f697e0SAnthony Wilson PROPERTY=CurrentBMCState 350b2398200SPatrick Williams state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY 35179f697e0SAnthony Wilson ;; 35279f697e0SAnthony Wilson chassisstate) 3530e044c48SPotin Lai OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID 35479f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 35579f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 35679f697e0SAnthony Wilson PROPERTY=CurrentPowerState 357b2398200SPatrick Williams state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY 35879f697e0SAnthony Wilson ;; 35979f697e0SAnthony Wilson hoststate) 3600e044c48SPotin Lai OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID 36179f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 36279f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 36379f697e0SAnthony Wilson PROPERTY=CurrentHostState 364b2398200SPatrick Williams state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY 36579f697e0SAnthony Wilson ;; 36686cffd9cSAlexander Filippov osstate) 3670e044c48SPotin Lai OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID 36886cffd9cSAlexander Filippov SERVICE=$(mapper get-service $OBJECT) 36986cffd9cSAlexander Filippov INTERFACE=$STATE_INTERFACE.OperatingSystem.Status 37086cffd9cSAlexander Filippov PROPERTY=OperatingSystemState 371b2398200SPatrick Williams state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY 37286cffd9cSAlexander Filippov ;; 37379f697e0SAnthony Wilson state|status) 37486cffd9cSAlexander Filippov for query in bmcstate chassisstate hoststate bootprogress osstate 37579f697e0SAnthony Wilson do 37679f697e0SAnthony Wilson handle_cmd $query 37779f697e0SAnthony Wilson done 378deb6bb45SAndrew Geissler check_and_warn_boot_block 37979f697e0SAnthony Wilson ;; 38050c5f88dSAnthony Wilson bootprogress) 3810e044c48SPotin Lai OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID 38250c5f88dSAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 38350c5f88dSAnthony Wilson INTERFACE=$STATE_INTERFACE.Boot.Progress 38450c5f88dSAnthony Wilson PROPERTY=BootProgress 385b2398200SPatrick Williams state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY 38650c5f88dSAnthony Wilson ;; 3870f35983dSAnthony Wilson power) 3880f35983dSAnthony Wilson OBJECT=/org/openbmc/control/power0 3890f35983dSAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 3900f35983dSAnthony Wilson INTERFACE=org.openbmc.control.Power 391*d182bff5SPatrick Williams for property in pgood state pgood_timeout; do 3920f35983dSAnthony Wilson # get_property can potentially return several 3930f35983dSAnthony Wilson # different formats of values, so we do the parsing outside 3940f35983dSAnthony Wilson # of get_property depending on the query. These queries 3950f35983dSAnthony Wilson # return 'i VALUE' formatted strings. 396*d182bff5SPatrick Williams STATE=$(get_property "$SERVICE" "$OBJECT" "$INTERFACE" "$property" | sed 's/i[ ^I]*//') 397b2398200SPatrick Williams printf "%s = %s\n" $property "$STATE" 3980f35983dSAnthony Wilson done 3990f35983dSAnthony Wilson ;; 400189cf248SAnthony Wilson chassiskill) 401189cf248SAnthony Wilson /usr/libexec/chassiskill 402189cf248SAnthony Wilson ;; 403a65d30d1SVishwanatha Subbanna hostrebootoff) 4040e044c48SPotin Lai OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot 4056d3a2c54SVishwanatha Subbanna SERVICE=$(mapper get-service $OBJECT) 4066d3a2c54SVishwanatha Subbanna INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy 4076d3a2c54SVishwanatha Subbanna PROPERTY=AutoReboot 4086d3a2c54SVishwanatha Subbanna VALUE=false 409b2398200SPatrick Williams set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE 4106d3a2c54SVishwanatha Subbanna ;; 4113191be88SAndrew Geissler hostrebootoffonetime) 4120e044c48SPotin Lai OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot/one_time 4133191be88SAndrew Geissler SERVICE=$(mapper get-service $OBJECT) 4143191be88SAndrew Geissler INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy 4153191be88SAndrew Geissler PROPERTY=AutoReboot 4163191be88SAndrew Geissler VALUE=false 417b2398200SPatrick Williams set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE 4183191be88SAndrew Geissler ;; 419a65d30d1SVishwanatha Subbanna hostrebooton) 4200e044c48SPotin Lai OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot 4216d3a2c54SVishwanatha Subbanna SERVICE=$(mapper get-service $OBJECT) 4226d3a2c54SVishwanatha Subbanna INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy 4236d3a2c54SVishwanatha Subbanna PROPERTY=AutoReboot 4246d3a2c54SVishwanatha Subbanna VALUE=true 425b2398200SPatrick Williams set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE 4266d3a2c54SVishwanatha Subbanna ;; 427a65d30d1SVishwanatha Subbanna bmcrebootoff) 428a65d30d1SVishwanatha Subbanna disable_bmc_reboot 429a65d30d1SVishwanatha Subbanna ;; 430a65d30d1SVishwanatha Subbanna bmcrebooton) 431a65d30d1SVishwanatha Subbanna enable_bmc_reboot 432a65d30d1SVishwanatha Subbanna ;; 4337a787dd7SVishwanatha Subbanna recoveryoff) 434a65d30d1SVishwanatha Subbanna handle_cmd hostrebootoff 435a65d30d1SVishwanatha Subbanna handle_cmd bmcrebootoff 4367a787dd7SVishwanatha Subbanna mask_systemd_target $HOST_TIMEOUT_TARGET 43784b3b29eSVishwanatha Subbanna mask_systemd_target $HOST_CRASH_TARGET 4387a787dd7SVishwanatha Subbanna ;; 4397a787dd7SVishwanatha Subbanna recoveryon) 440a65d30d1SVishwanatha Subbanna handle_cmd hostrebooton 441a65d30d1SVishwanatha Subbanna handle_cmd bmcrebooton 4427a787dd7SVishwanatha Subbanna unmask_systemd_target $HOST_TIMEOUT_TARGET 44384b3b29eSVishwanatha Subbanna unmask_systemd_target $HOST_CRASH_TARGET 4447a787dd7SVishwanatha Subbanna ;; 4453b7b5619SAndrew Geissler listbootblock) 4463b7b5619SAndrew Geissler blockingErrors=$(check_boot_block_errors) 4473b7b5619SAndrew Geissler if [ -z "$blockingErrors" ]; then 4483b7b5619SAndrew Geissler echo "No blocking errors present" 4493b7b5619SAndrew Geissler else 4503b7b5619SAndrew Geissler echo "$blockingErrors" 4513b7b5619SAndrew Geissler fi 4523b7b5619SAndrew Geissler ;; 453295ee4fbSAndrew Geissler listlogs) 454295ee4fbSAndrew Geissler list_logs 455295ee4fbSAndrew Geissler ;; 456d8c63204SAndrew Geissler showlog) 457b2398200SPatrick Williams show_log "$2" 458d8c63204SAndrew Geissler ;; 45942f2898dSAndrew Geissler deletelogs) 46042f2898dSAndrew Geissler delete_logs 46142f2898dSAndrew Geissler ;; 462ad1afe58SAndrew Geissler stopofftargets) 463ad1afe58SAndrew Geissler stop_off_targets 464ad1afe58SAndrew Geissler ;; 46579f697e0SAnthony Wilson *) 466ea87db40SAnthony Wilson print_usage_err "Invalid command '$1'" 46779f697e0SAnthony Wilson ;; 46879f697e0SAnthony Wilson esac 46979f697e0SAnthony Wilson} 47079f697e0SAnthony Wilson 471d8779cd8SAndrew Geisslershiftcnt=0 472ea87db40SAnthony Wilsonfor arg in "$@"; do 473ea87db40SAnthony Wilson case $arg in 474acf54d08SAnthony Wilson -w|--wait) 475acf54d08SAnthony Wilson G_WAIT=30 476d8779cd8SAndrew Geissler shiftcnt=$((shiftcnt+1)) 477acf54d08SAnthony Wilson continue 478acf54d08SAnthony Wilson ;; 479ea87db40SAnthony Wilson -h|--help) 480ea87db40SAnthony Wilson print_help 481ea87db40SAnthony Wilson ;; 48260c3ac8cSAndrew Jeffery -v|--verbose) 48360c3ac8cSAndrew Jeffery G_VERBOSE=y 484d8779cd8SAndrew Geissler shiftcnt=$((shiftcnt+1)) 48560c3ac8cSAndrew Jeffery ;; 4860e044c48SPotin Lai -i=*|--id=*) 4870e044c48SPotin Lai G_INSTANCE_ID="${arg#*=}" 4880e044c48SPotin Lai shiftcnt=$((shiftcnt+1)) 4890e044c48SPotin Lai ;; 490ea87db40SAnthony Wilson -*) 491ea87db40SAnthony Wilson print_usage_err "Unknown option: $arg" 492ea87db40SAnthony Wilson ;; 493ea87db40SAnthony Wilson *) 494acf54d08SAnthony Wilson G_ORIG_CMD=$arg 495d8779cd8SAndrew Geissler # shift out the optional parameters 496d8779cd8SAndrew Geissler shift $shiftcnt 497d8c63204SAndrew Geissler # pass all arguments to handle_cmd in case command takes additional 498d8c63204SAndrew Geissler # parameters 499d8c63204SAndrew Geissler handle_cmd "$@" 500ea87db40SAnthony Wilson break 501ea87db40SAnthony Wilson ;; 502ea87db40SAnthony Wilson esac 503ea87db40SAnthony Wilsondone 504