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