Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 1 | #!/bin/bash -e |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 2 | |
| 3 | set -euo pipefail |
| 4 | |
Anthony Wilson | 189cf24 | 2018-10-23 01:18:21 -0500 | [diff] [blame] | 5 | OPTS="bmcstate,bootprogress,chassiskill,chassisoff,chassison,chassisstate,hoststate,\ |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 6 | osstate,power,poweroff,poweron,state,status,hostrebootoff,hostrebooton,recoveryoff,recoveryon,\ |
Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 7 | bmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs" |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 8 | |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 9 | USAGE="Usage: obmcutil [-h] [--wait] [--verbose] |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 10 | {$OPTS}" |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 11 | |
| 12 | INTERFACE_ROOT=xyz.openbmc_project |
| 13 | STATE_INTERFACE=$INTERFACE_ROOT.State |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 14 | CONTROL_INTERFACE=$INTERFACE_ROOT.Control |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 15 | |
| 16 | OBJECT_ROOT=/xyz/openbmc_project |
| 17 | STATE_OBJECT=$OBJECT_ROOT/state |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 18 | CONTROL_OBJECT=$OBJECT_ROOT/control |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 19 | |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 20 | HOST_TIMEOUT_TARGET=obmc-host-timeout@0.target |
Vishwanatha Subbanna | 84b3b29 | 2019-11-04 05:43:19 -0600 | [diff] [blame] | 21 | HOST_CRASH_TARGET=obmc-host-crash@0.target |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 22 | |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 23 | ## NOTE: The following global variables are used only in the run_timeout cmd. |
| 24 | ## By declaring these globally instead of passing them through the |
| 25 | ## intermediary functions, which may not be "best practice", the readability |
| 26 | ## and cleanliness of the code should at least be increased. |
| 27 | |
| 28 | # The command passed in to be executed (e.g. poweron/off, status, etc.) |
| 29 | # This will be be used in some instances of error reporting |
| 30 | G_ORIG_CMD= |
| 31 | # The state an interface should be in after executing the requested command. |
| 32 | G_REQUESTED_STATE= |
| 33 | # The query to run during a poweron/off or chassison/off to check that |
| 34 | # the requested state (G_REQUESTED_STATE) of the interface has been reached. |
| 35 | G_QUERY= |
| 36 | # Wait the set period of time for state transitions to be successful before |
| 37 | # continuing on with the program or reporting an error if timeout reached. |
| 38 | G_WAIT= |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 39 | # Print the journal to the console |
| 40 | G_VERBOSE= |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 41 | |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 42 | print_help () |
| 43 | { |
| 44 | echo "$USAGE" |
| 45 | echo "" |
| 46 | echo "positional arguments:" |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 47 | echo " {$OPTS}" |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 48 | echo "" |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 49 | echo "Examples:" |
| 50 | echo "" |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 51 | echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state" |
Andrew Geissler | 3191be8 | 2020-10-23 10:45:55 -0500 | [diff] [blame] | 52 | echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from" |
| 53 | echo " Quiesce state for a single boot" |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 54 | echo "obmcutil hostrebooton Enable auto reboot of Host from Quiesce state" |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 55 | echo "" |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 56 | echo "obmcutil bmcrebootoff Disable reboot of BMC" |
| 57 | echo "obmcutil bmcrebooton Enable reboot of BMC" |
| 58 | echo "" |
| 59 | echo "obmcutil recoveryoff Disable handling boot watchdog timeout and host crash" |
| 60 | echo " Also, disable BMC and Host auto reboots" |
| 61 | echo "" |
| 62 | echo "obmcutil recoveryon Enable handling boot watchdog timeout and host crash" |
| 63 | echo " Also, enable BMC and Host auto reboots" |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 64 | echo "" |
Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 65 | echo "obmcutil listbootblock Check for and list any errors blocking the boot" |
| 66 | echo " of the system" |
| 67 | echo "" |
Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 68 | echo "obmcutil listlogs List all phosphor-logging entries on the" |
| 69 | echo " system" |
| 70 | echo "" |
Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 71 | echo "obmcutil showlog <log> Display details of input log. Format of <log>" |
| 72 | echo " should match listlogs output" |
| 73 | echo "" |
Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 74 | echo "obmcutil deletelogs Delete all phosphor-logging entries from" |
| 75 | echo " system" |
| 76 | echo "" |
Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 77 | echo "optional arguments (must precede the positional options above):" |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 78 | echo " -h, --help show this help message and exit" |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 79 | echo " -w, --wait block until state transition succeeds or fails" |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 80 | echo " -v, --verbose print the journal to stdout if --wait is supplied" |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 81 | exit 0 |
| 82 | } |
| 83 | |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 84 | run_timeout () |
| 85 | { |
| 86 | local timeout="$1"; shift |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 87 | local cmd="$*" |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 88 | local verbose_child= |
| 89 | |
Andrew Jeffery | 2869a92 | 2019-10-18 14:42:34 +1030 | [diff] [blame] | 90 | if [ -n "$G_VERBOSE" ]; then |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 91 | journalctl -f & |
| 92 | verbose_child=$! |
| 93 | fi |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 94 | |
| 95 | $cmd |
| 96 | |
| 97 | # Run a background query for the transition to the expected state |
| 98 | # This will be killed if the transition doesn't succeed within |
| 99 | # a timeout period. |
| 100 | ( |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 101 | while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 102 | sleep 1 |
| 103 | done |
| 104 | ) & |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 105 | wait_child=$! |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 106 | |
| 107 | # Could be bad if process is killed before 'timeout' occurs if |
| 108 | # transition doesn't succeed. |
| 109 | trap -- "" SIGTERM |
| 110 | |
| 111 | # Workaround for lack of 'timeout' command. |
| 112 | ( |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 113 | sleep "$timeout" |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 114 | kill $wait_child |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 115 | ) > /dev/null 2>&1 & |
| 116 | |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 117 | if ! wait $wait_child; then |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 118 | echo "Unable to confirm '$G_ORIG_CMD' success" \ |
| 119 | "within timeout period (${timeout}s)" |
| 120 | fi |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 121 | |
Andrew Jeffery | 8be7029 | 2019-11-01 08:56:49 +1030 | [diff] [blame] | 122 | if [ -n "$verbose_child" ]; then |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 123 | kill $verbose_child |
| 124 | fi |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | run_cmd () |
| 128 | { |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 129 | local cmd="$*"; |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 130 | |
| 131 | if [ -n "$G_WAIT" ]; then |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 132 | run_timeout "$G_WAIT" "$cmd" |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 133 | else |
| 134 | $cmd |
| 135 | fi |
| 136 | } |
| 137 | |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 138 | set_property () |
| 139 | { |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 140 | run_cmd busctl set-property "$@" |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 141 | } |
| 142 | |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 143 | get_property () |
| 144 | { |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 145 | G_WAIT="" |
| 146 | run_cmd busctl get-property "$@" |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | state_query () |
| 150 | { |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 151 | local state |
| 152 | state=$(get_property "$@" | cut -d '"' -f2) |
| 153 | printf "%-20s: %s\n" "$4" "$state" |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 154 | } |
| 155 | |
Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 156 | print_usage_err () |
| 157 | { |
| 158 | echo "ERROR: $1" >&2 |
| 159 | echo "$USAGE" |
| 160 | exit 1 |
| 161 | } |
| 162 | |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 163 | mask_systemd_target () |
| 164 | { |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 165 | target="$*" |
| 166 | systemctl mask "$target" |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | unmask_systemd_target () |
| 170 | { |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 171 | target="$*" |
| 172 | systemctl unmask "$target" |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 175 | disable_bmc_reboot () |
| 176 | { |
| 177 | dir="/run/systemd/system/" |
| 178 | file="reboot-guard.conf" |
| 179 | units=("reboot" "poweroff" "halt") |
| 180 | |
| 181 | for unit in "${units[@]}"; do |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 182 | mkdir -p "${dir}${unit}.target.d" |
| 183 | echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}" |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 184 | done |
| 185 | } |
| 186 | |
| 187 | enable_bmc_reboot () |
| 188 | { |
| 189 | dir="/run/systemd/system/" |
| 190 | file="reboot-guard.conf" |
| 191 | units=("reboot" "poweroff" "halt") |
| 192 | |
| 193 | for unit in "${units[@]}"; do |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 194 | rm -rf "${dir}${unit}.target.d/${file}" |
| 195 | rm -rf "${dir}${unit}.target.d" |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 196 | done |
| 197 | } |
| 198 | |
Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 199 | # will write blocking errors to stdout |
| 200 | check_boot_block_errors () |
| 201 | { |
| 202 | # array of boot block objects |
| 203 | blockArray=() |
| 204 | |
| 205 | # Look for any objects under logging that implement the |
| 206 | # xyz.openbmc_project.Logging.ErrorBlocksTransition |
| 207 | subtree="$(busctl call xyz.openbmc_project.ObjectMapper \ |
| 208 | /xyz/openbmc_project/object_mapper \ |
| 209 | xyz.openbmc_project.ObjectMapper \ |
| 210 | GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \ |
| 211 | xyz.openbmc_project.Logging.ErrorBlocksTransition)" |
| 212 | |
| 213 | # remove quotation marks |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 214 | # shellcheck disable=SC2001 |
| 215 | subtree="$(echo "$subtree" | sed 's/\"//g')" |
Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 216 | |
| 217 | for entry in $subtree; do |
| 218 | if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 219 | blockArray+=( "$entry" ) |
Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 220 | fi |
| 221 | done |
| 222 | |
| 223 | # now find associated error log for each boot block error |
| 224 | for berror in "${blockArray[@]}"; do |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 225 | assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \ |
Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 226 | org.freedesktop.DBus.Properties Get \ |
| 227 | ss xyz.openbmc_project.Association.Definitions Associations)" |
| 228 | |
| 229 | # remove quotation marks |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 230 | # shellcheck disable=SC2001 |
| 231 | assocs="$(echo "$assocs" | sed 's/\"//g')" |
Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 232 | |
| 233 | for entry in $assocs; do |
| 234 | if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then |
| 235 | echo "Blocking Error: $entry" |
| 236 | fi |
| 237 | done |
| 238 | done |
| 239 | } |
| 240 | |
Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 241 | # helper function to check for boot block errors and notify user |
| 242 | check_and_warn_boot_block() |
| 243 | { |
| 244 | blockingErrors=$(check_boot_block_errors) |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 245 | if [ -n "$blockingErrors" ]; then |
Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 246 | echo !!!!!!!!!! |
| 247 | echo "WARNING! System has blocking errors that will prevent boot" |
| 248 | echo "$blockingErrors" |
| 249 | echo !!!!!!!!!! |
| 250 | fi |
| 251 | } |
| 252 | |
Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 253 | # list all phosphor-logging entries |
| 254 | list_logs() |
| 255 | { |
| 256 | # Look for any objects under logging that implement the |
| 257 | # xyz.openbmc_project.Logging.Entry |
| 258 | busctl -j call xyz.openbmc_project.ObjectMapper \ |
| 259 | /xyz/openbmc_project/object_mapper \ |
| 260 | xyz.openbmc_project.ObjectMapper \ |
| 261 | GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \ |
| 262 | xyz.openbmc_project.Logging.Entry |
| 263 | } |
| 264 | |
Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 265 | # display input log details |
| 266 | show_log() |
| 267 | { |
| 268 | busctl -j call xyz.openbmc_project.Logging \ |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 269 | "$1" \ |
Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 270 | org.freedesktop.DBus.Properties \ |
| 271 | GetAll s xyz.openbmc_project.Logging.Entry |
| 272 | } |
| 273 | |
Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 274 | # delete all phosphor-logging entries |
| 275 | delete_logs() |
| 276 | { |
| 277 | busctl call xyz.openbmc_project.Logging \ |
| 278 | /xyz/openbmc_project/logging \ |
| 279 | xyz.openbmc_project.Collection.DeleteAll DeleteAll |
| 280 | } |
| 281 | |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 282 | handle_cmd () |
| 283 | { |
| 284 | case "$1" in |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 285 | chassisoff) |
| 286 | OBJECT=$STATE_OBJECT/chassis0 |
| 287 | SERVICE=$(mapper get-service $OBJECT) |
| 288 | INTERFACE=$STATE_INTERFACE.Chassis |
| 289 | PROPERTY=RequestedPowerTransition |
| 290 | VALUE=$INTERFACE.Transition.Off |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 291 | G_REQUESTED_STATE=$INTERFACE.PowerState.Off |
| 292 | G_QUERY="chassisstate" |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 293 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 294 | ;; |
| 295 | chassison) |
Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 296 | check_and_warn_boot_block |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 297 | OBJECT=$STATE_OBJECT/chassis0 |
| 298 | SERVICE=$(mapper get-service $OBJECT) |
| 299 | INTERFACE=$STATE_INTERFACE.Chassis |
| 300 | PROPERTY=RequestedPowerTransition |
| 301 | VALUE=$INTERFACE.Transition.On |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 302 | G_REQUESTED_STATE=$INTERFACE.PowerState.On |
| 303 | G_QUERY="chassisstate" |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 304 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 305 | ;; |
| 306 | poweroff) |
| 307 | OBJECT=$STATE_OBJECT/host0 |
| 308 | SERVICE=$(mapper get-service $OBJECT) |
| 309 | INTERFACE=$STATE_INTERFACE.Host |
| 310 | PROPERTY=RequestedHostTransition |
| 311 | VALUE=$INTERFACE.Transition.Off |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 312 | G_REQUESTED_STATE=$INTERFACE.HostState.Off |
| 313 | G_QUERY="hoststate" |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 314 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 315 | ;; |
| 316 | poweron) |
Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 317 | check_and_warn_boot_block |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 318 | OBJECT=$STATE_OBJECT/host0 |
| 319 | SERVICE=$(mapper get-service $OBJECT) |
| 320 | INTERFACE=$STATE_INTERFACE.Host |
| 321 | PROPERTY=RequestedHostTransition |
| 322 | VALUE=$INTERFACE.Transition.On |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 323 | G_REQUESTED_STATE=$INTERFACE.HostState.Running |
| 324 | G_QUERY="hoststate" |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 325 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE |
Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 326 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 327 | bmcstate) |
| 328 | OBJECT=$STATE_OBJECT/bmc0 |
| 329 | SERVICE=$(mapper get-service $OBJECT) |
| 330 | INTERFACE=$STATE_INTERFACE.BMC |
| 331 | PROPERTY=CurrentBMCState |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 332 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 333 | ;; |
| 334 | chassisstate) |
| 335 | OBJECT=$STATE_OBJECT/chassis0 |
| 336 | SERVICE=$(mapper get-service $OBJECT) |
| 337 | INTERFACE=$STATE_INTERFACE.Chassis |
| 338 | PROPERTY=CurrentPowerState |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 339 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 340 | ;; |
| 341 | hoststate) |
| 342 | OBJECT=$STATE_OBJECT/host0 |
| 343 | SERVICE=$(mapper get-service $OBJECT) |
| 344 | INTERFACE=$STATE_INTERFACE.Host |
| 345 | PROPERTY=CurrentHostState |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 346 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 347 | ;; |
Alexander Filippov | 86cffd9 | 2019-04-03 16:29:57 +0300 | [diff] [blame] | 348 | osstate) |
| 349 | OBJECT=$STATE_OBJECT/host0 |
| 350 | SERVICE=$(mapper get-service $OBJECT) |
| 351 | INTERFACE=$STATE_INTERFACE.OperatingSystem.Status |
| 352 | PROPERTY=OperatingSystemState |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 353 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY |
Alexander Filippov | 86cffd9 | 2019-04-03 16:29:57 +0300 | [diff] [blame] | 354 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 355 | state|status) |
Alexander Filippov | 86cffd9 | 2019-04-03 16:29:57 +0300 | [diff] [blame] | 356 | for query in bmcstate chassisstate hoststate bootprogress osstate |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 357 | do |
| 358 | handle_cmd $query |
| 359 | done |
Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 360 | check_and_warn_boot_block |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 361 | ;; |
Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame] | 362 | bootprogress) |
| 363 | OBJECT=$STATE_OBJECT/host0 |
| 364 | SERVICE=$(mapper get-service $OBJECT) |
| 365 | INTERFACE=$STATE_INTERFACE.Boot.Progress |
| 366 | PROPERTY=BootProgress |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 367 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY |
Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame] | 368 | ;; |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 369 | power) |
| 370 | OBJECT=/org/openbmc/control/power0 |
| 371 | SERVICE=$(mapper get-service $OBJECT) |
| 372 | INTERFACE=org.openbmc.control.Power |
| 373 | for property in pgood state pgood_timeout |
| 374 | do |
| 375 | # get_property can potentially return several |
| 376 | # different formats of values, so we do the parsing outside |
| 377 | # of get_property depending on the query. These queries |
| 378 | # return 'i VALUE' formatted strings. |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 379 | STATE=$(get_property "$SERVICE" $OBJECT $INTERFACE $property \ |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 380 | | sed 's/i[ ^I]*//') |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 381 | printf "%s = %s\n" $property "$STATE" |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 382 | done |
| 383 | ;; |
Anthony Wilson | 189cf24 | 2018-10-23 01:18:21 -0500 | [diff] [blame] | 384 | chassiskill) |
| 385 | /usr/libexec/chassiskill |
| 386 | ;; |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 387 | hostrebootoff) |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 388 | OBJECT=$CONTROL_OBJECT/host0/auto_reboot |
| 389 | SERVICE=$(mapper get-service $OBJECT) |
| 390 | INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy |
| 391 | PROPERTY=AutoReboot |
| 392 | VALUE=false |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 393 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 394 | ;; |
Andrew Geissler | 3191be8 | 2020-10-23 10:45:55 -0500 | [diff] [blame] | 395 | hostrebootoffonetime) |
| 396 | OBJECT=$CONTROL_OBJECT/host0/auto_reboot/one_time |
| 397 | SERVICE=$(mapper get-service $OBJECT) |
| 398 | INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy |
| 399 | PROPERTY=AutoReboot |
| 400 | VALUE=false |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 401 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE |
Andrew Geissler | 3191be8 | 2020-10-23 10:45:55 -0500 | [diff] [blame] | 402 | ;; |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 403 | hostrebooton) |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 404 | OBJECT=$CONTROL_OBJECT/host0/auto_reboot |
| 405 | SERVICE=$(mapper get-service $OBJECT) |
| 406 | INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy |
| 407 | PROPERTY=AutoReboot |
| 408 | VALUE=true |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 409 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE |
Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 410 | ;; |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 411 | bmcrebootoff) |
| 412 | disable_bmc_reboot |
| 413 | ;; |
| 414 | bmcrebooton) |
| 415 | enable_bmc_reboot |
| 416 | ;; |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 417 | recoveryoff) |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 418 | handle_cmd hostrebootoff |
| 419 | handle_cmd bmcrebootoff |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 420 | mask_systemd_target $HOST_TIMEOUT_TARGET |
Vishwanatha Subbanna | 84b3b29 | 2019-11-04 05:43:19 -0600 | [diff] [blame] | 421 | mask_systemd_target $HOST_CRASH_TARGET |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 422 | ;; |
| 423 | recoveryon) |
Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 424 | handle_cmd hostrebooton |
| 425 | handle_cmd bmcrebooton |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 426 | unmask_systemd_target $HOST_TIMEOUT_TARGET |
Vishwanatha Subbanna | 84b3b29 | 2019-11-04 05:43:19 -0600 | [diff] [blame] | 427 | unmask_systemd_target $HOST_CRASH_TARGET |
Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 428 | ;; |
Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 429 | listbootblock) |
| 430 | blockingErrors=$(check_boot_block_errors) |
| 431 | if [ -z "$blockingErrors" ]; then |
| 432 | echo "No blocking errors present" |
| 433 | else |
| 434 | echo "$blockingErrors" |
| 435 | fi |
| 436 | ;; |
Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 437 | listlogs) |
| 438 | list_logs |
| 439 | ;; |
Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 440 | showlog) |
Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 441 | show_log "$2" |
Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 442 | ;; |
Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 443 | deletelogs) |
| 444 | delete_logs |
| 445 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 446 | *) |
Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 447 | print_usage_err "Invalid command '$1'" |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 448 | ;; |
| 449 | esac |
| 450 | } |
| 451 | |
Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 452 | shiftcnt=0 |
Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 453 | for arg in "$@"; do |
| 454 | case $arg in |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 455 | -w|--wait) |
| 456 | G_WAIT=30 |
Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 457 | shiftcnt=$((shiftcnt+1)) |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 458 | continue |
| 459 | ;; |
Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 460 | -h|--help) |
| 461 | print_help |
| 462 | ;; |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 463 | -v|--verbose) |
| 464 | G_VERBOSE=y |
Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 465 | shiftcnt=$((shiftcnt+1)) |
Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 466 | ;; |
Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 467 | -*) |
| 468 | print_usage_err "Unknown option: $arg" |
| 469 | ;; |
| 470 | *) |
Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 471 | G_ORIG_CMD=$arg |
Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 472 | # shift out the optional parameters |
| 473 | shift $shiftcnt |
Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 474 | # pass all arguments to handle_cmd in case command takes additional |
| 475 | # parameters |
| 476 | handle_cmd "$@" |
Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 477 | break |
| 478 | ;; |
| 479 | esac |
| 480 | done |