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