blob: 9cd931f9ea64a622da9a3a7c0e4025c3d7bcfd92 [file] [log] [blame]
Patrick Williamsb2398202021-04-13 20:53:26 -05001#!/bin/bash -e
Anthony Wilson79f697e2018-09-13 13:48:52 -05002
3set -euo pipefail
4
Anthony Wilson189cf242018-10-23 01:18:21 -05005OPTS="bmcstate,bootprogress,chassiskill,chassisoff,chassison,chassisstate,hoststate,\
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -06006osstate,power,poweroff,poweron,state,status,hostrebootoff,hostrebooton,recoveryoff,recoveryon,\
Andrew Geisslerad1afe52022-02-23 16:07:06 -06007bmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs, stopofftargets"
Anthony Wilson0f359832018-09-13 14:28:07 -05008
Potin Lai0e044c42022-05-13 23:42:31 +08009USAGE="Usage: obmcutil [-h] [--wait] [--verbose] [--id=<INSTANCE_ID>]
Patrick Williamsd182bff2022-12-08 06:39:12 -060010{$OPTS}"
Anthony Wilson79f697e2018-09-13 13:48:52 -050011
12INTERFACE_ROOT=xyz.openbmc_project
13STATE_INTERFACE=$INTERFACE_ROOT.State
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050014CONTROL_INTERFACE=$INTERFACE_ROOT.Control
Anthony Wilson79f697e2018-09-13 13:48:52 -050015
16OBJECT_ROOT=/xyz/openbmc_project
17STATE_OBJECT=$OBJECT_ROOT/state
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050018CONTROL_OBJECT=$OBJECT_ROOT/control
Anthony Wilson79f697e2018-09-13 13:48:52 -050019
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -050020HOST_TIMEOUT_TARGET=obmc-host-timeout@0.target
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -060021HOST_CRASH_TARGET=obmc-host-crash@0.target
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -050022
Anthony Wilsonacf54d02018-09-20 15:19:28 -050023## 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
30G_ORIG_CMD=
31# The state an interface should be in after executing the requested command.
32G_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.
35G_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.
38G_WAIT=
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093039# Print the journal to the console
40G_VERBOSE=
Potin Lai0e044c42022-05-13 23:42:31 +080041# Instance id, default 0
42G_INSTANCE_ID="0"
Anthony Wilsonacf54d02018-09-20 15:19:28 -050043
Patrick Williamsd182bff2022-12-08 06:39:12 -060044function print_help()
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050045{
46 echo "$USAGE"
47 echo ""
48 echo "positional arguments:"
Anthony Wilson0f359832018-09-13 14:28:07 -050049 echo " {$OPTS}"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050050 echo ""
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050051 echo "Examples:"
52 echo ""
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060053 echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state"
Andrew Geissler3191be82020-10-23 10:45:55 -050054 echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from"
55 echo " Quiesce state for a single boot"
Andrew Geisslerad1afe52022-02-23 16:07:06 -060056 echo "obmcutil hostrebooton Enable auto reboot of Host from Quiesce state"
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050057 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060058 echo "obmcutil bmcrebootoff Disable reboot of BMC"
59 echo "obmcutil bmcrebooton Enable reboot of BMC"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060060 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060061 echo "obmcutil recoveryoff Disable handling boot watchdog timeout and host crash"
62 echo " Also, disable BMC and Host auto reboots"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060063 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060064 echo "obmcutil recoveryon Enable handling boot watchdog timeout and host crash"
65 echo " Also, enable BMC and Host auto reboots"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -050066 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060067 echo "obmcutil listbootblock Check for and list any errors blocking the boot"
68 echo " of the system"
Andrew Geissler3b7b5612020-05-14 10:45:29 -050069 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060070 echo "obmcutil listlogs List all phosphor-logging entries on the"
71 echo " system"
Andrew Geissler295ee4f2020-05-14 14:14:05 -050072 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060073 echo "obmcutil showlog <log> Display details of input log. Format of <log>"
74 echo " should match listlogs output"
Andrew Geisslerd8c63202020-05-14 15:06:31 -050075 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060076 echo "obmcutil deletelogs Delete all phosphor-logging entries from"
77 echo " system"
78 echo "obmcutil stopofftargets Manually stop all obmc targets in power off"
79 echo " path"
Andrew Geissler42f28982020-05-14 15:12:42 -050080 echo ""
Andrew Geisslerd8779cd2020-06-11 10:48:40 -050081 echo "optional arguments (must precede the positional options above):"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050082 echo " -h, --help show this help message and exit"
Anthony Wilsonacf54d02018-09-20 15:19:28 -050083 echo " -w, --wait block until state transition succeeds or fails"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093084 echo " -v, --verbose print the journal to stdout if --wait is supplied"
Potin Lai0e044c42022-05-13 23:42:31 +080085 echo " -i, -id instance id, default 0"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050086 exit 0
87}
88
Patrick Williamsd182bff2022-12-08 06:39:12 -060089function run_timeout()
Anthony Wilsonacf54d02018-09-20 15:19:28 -050090{
91 local timeout="$1"; shift
Patrick Williamsb2398202021-04-13 20:53:26 -050092 local cmd="$*"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093093 local verbose_child=
94
Andrew Jeffery2869a922019-10-18 14:42:34 +103095 if [ -n "$G_VERBOSE" ]; then
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093096 journalctl -f &
97 verbose_child=$!
98 fi
Anthony Wilsonacf54d02018-09-20 15:19:28 -050099
100 $cmd
101
102 # Run a background query for the transition to the expected state
103 # This will be killed if the transition doesn't succeed within
104 # a timeout period.
105 (
Patrick Williamsb2398202021-04-13 20:53:26 -0500106 while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500107 sleep 1
108 done
109 ) &
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930110 wait_child=$!
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500111
112 # Could be bad if process is killed before 'timeout' occurs if
113 # transition doesn't succeed.
114 trap -- "" SIGTERM
115
116 # Workaround for lack of 'timeout' command.
117 (
Patrick Williamsb2398202021-04-13 20:53:26 -0500118 sleep "$timeout"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930119 kill $wait_child
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500120 ) > /dev/null 2>&1 &
121
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930122 if ! wait $wait_child; then
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500123 echo "Unable to confirm '$G_ORIG_CMD' success" \
Patrick Williamsd182bff2022-12-08 06:39:12 -0600124 "within timeout period (${timeout}s)"
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500125 fi
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930126
Andrew Jeffery8be70292019-11-01 08:56:49 +1030127 if [ -n "$verbose_child" ]; then
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930128 kill $verbose_child
129 fi
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500130}
131
Patrick Williamsd182bff2022-12-08 06:39:12 -0600132function run_cmd()
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500133{
Patrick Williamsb2398202021-04-13 20:53:26 -0500134 local cmd="$*";
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500135
136 if [ -n "$G_WAIT" ]; then
Patrick Williamsb2398202021-04-13 20:53:26 -0500137 run_timeout "$G_WAIT" "$cmd"
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500138 else
139 $cmd
140 fi
141}
142
Patrick Williamsd182bff2022-12-08 06:39:12 -0600143function set_property()
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500144{
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500145 run_cmd busctl set-property "$@"
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500146}
147
Patrick Williamsd182bff2022-12-08 06:39:12 -0600148function get_property()
Anthony Wilson79f697e2018-09-13 13:48:52 -0500149{
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500150 G_WAIT=""
151 run_cmd busctl get-property "$@"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500152}
153
Patrick Williamsd182bff2022-12-08 06:39:12 -0600154function state_query()
Anthony Wilson79f697e2018-09-13 13:48:52 -0500155{
Patrick Williamsb2398202021-04-13 20:53:26 -0500156 local state
157 state=$(get_property "$@" | cut -d '"' -f2)
158 printf "%-20s: %s\n" "$4" "$state"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500159}
160
Patrick Williamsd182bff2022-12-08 06:39:12 -0600161function print_usage_err()
Anthony Wilsonea87db42018-09-26 16:06:38 -0500162{
163 echo "ERROR: $1" >&2
164 echo "$USAGE"
165 exit 1
166}
167
Patrick Williamsd182bff2022-12-08 06:39:12 -0600168function mask_systemd_target()
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500169{
Patrick Williamsb2398202021-04-13 20:53:26 -0500170 target="$*"
171 systemctl mask "$target"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500172}
173
Patrick Williamsd182bff2022-12-08 06:39:12 -0600174function unmask_systemd_target()
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500175{
Patrick Williamsb2398202021-04-13 20:53:26 -0500176 target="$*"
177 systemctl unmask "$target"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500178}
179
Patrick Williamsd182bff2022-12-08 06:39:12 -0600180function disable_bmc_reboot()
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600181{
182 dir="/run/systemd/system/"
183 file="reboot-guard.conf"
184 units=("reboot" "poweroff" "halt")
185
186 for unit in "${units[@]}"; do
Patrick Williamsb2398202021-04-13 20:53:26 -0500187 mkdir -p "${dir}${unit}.target.d"
188 echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600189 done
190}
191
Patrick Williamsd182bff2022-12-08 06:39:12 -0600192function enable_bmc_reboot()
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600193{
194 dir="/run/systemd/system/"
195 file="reboot-guard.conf"
196 units=("reboot" "poweroff" "halt")
197
198 for unit in "${units[@]}"; do
Patrick Williamsb2398202021-04-13 20:53:26 -0500199 rm -rf "${dir}${unit}.target.d/${file}"
200 rm -rf "${dir}${unit}.target.d"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600201 done
202}
203
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500204# will write blocking errors to stdout
Patrick Williamsd182bff2022-12-08 06:39:12 -0600205function check_boot_block_errors()
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500206{
207 # array of boot block objects
208 blockArray=()
209
210 # Look for any objects under logging that implement the
211 # xyz.openbmc_project.Logging.ErrorBlocksTransition
212 subtree="$(busctl call xyz.openbmc_project.ObjectMapper \
213 /xyz/openbmc_project/object_mapper \
214 xyz.openbmc_project.ObjectMapper \
215 GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \
216 xyz.openbmc_project.Logging.ErrorBlocksTransition)"
217
218 # remove quotation marks
Patrick Williamsb2398202021-04-13 20:53:26 -0500219 # shellcheck disable=SC2001
220 subtree="$(echo "$subtree" | sed 's/\"//g')"
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500221
222 for entry in $subtree; do
223 if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then
Patrick Williamsb2398202021-04-13 20:53:26 -0500224 blockArray+=( "$entry" )
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500225 fi
226 done
227
228 # now find associated error log for each boot block error
229 for berror in "${blockArray[@]}"; do
Patrick Williamsb2398202021-04-13 20:53:26 -0500230 assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500231 org.freedesktop.DBus.Properties Get \
232 ss xyz.openbmc_project.Association.Definitions Associations)"
233
234 # remove quotation marks
Patrick Williamsb2398202021-04-13 20:53:26 -0500235 # shellcheck disable=SC2001
236 assocs="$(echo "$assocs" | sed 's/\"//g')"
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500237
238 for entry in $assocs; do
239 if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then
240 echo "Blocking Error: $entry"
241 fi
242 done
243 done
244}
245
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500246# helper function to check for boot block errors and notify user
Patrick Williamsd182bff2022-12-08 06:39:12 -0600247function check_and_warn_boot_block()
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500248{
249 blockingErrors=$(check_boot_block_errors)
Patrick Williamsb2398202021-04-13 20:53:26 -0500250 if [ -n "$blockingErrors" ]; then
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500251 echo !!!!!!!!!!
252 echo "WARNING! System has blocking errors that will prevent boot"
253 echo "$blockingErrors"
254 echo !!!!!!!!!!
255 fi
256}
257
Andrew Geissler295ee4f2020-05-14 14:14:05 -0500258# list all phosphor-logging entries
Patrick Williamsd182bff2022-12-08 06:39:12 -0600259function list_logs()
Andrew Geissler295ee4f2020-05-14 14:14:05 -0500260{
261 # Look for any objects under logging that implement the
262 # xyz.openbmc_project.Logging.Entry
263 busctl -j call xyz.openbmc_project.ObjectMapper \
Patrick Williamsd182bff2022-12-08 06:39:12 -0600264 /xyz/openbmc_project/object_mapper \
265 xyz.openbmc_project.ObjectMapper \
266 GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \
267 xyz.openbmc_project.Logging.Entry
Andrew Geissler295ee4f2020-05-14 14:14:05 -0500268}
269
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500270# display input log details
Patrick Williamsd182bff2022-12-08 06:39:12 -0600271function show_log()
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500272{
273 busctl -j call xyz.openbmc_project.Logging \
Patrick Williamsd182bff2022-12-08 06:39:12 -0600274 "$1" \
275 org.freedesktop.DBus.Properties \
276 GetAll s xyz.openbmc_project.Logging.Entry
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500277}
278
Andrew Geissler42f28982020-05-14 15:12:42 -0500279# delete all phosphor-logging entries
Patrick Williamsd182bff2022-12-08 06:39:12 -0600280function delete_logs()
Andrew Geissler42f28982020-05-14 15:12:42 -0500281{
282 busctl call xyz.openbmc_project.Logging \
Patrick Williamsd182bff2022-12-08 06:39:12 -0600283 /xyz/openbmc_project/logging \
284 xyz.openbmc_project.Collection.DeleteAll DeleteAll
Andrew Geissler42f28982020-05-14 15:12:42 -0500285}
286
Andrew Geisslerad1afe52022-02-23 16:07:06 -0600287# stop all targets associated with powering off a system
Patrick Williamsd182bff2022-12-08 06:39:12 -0600288function stop_off_targets()
Andrew Geisslerad1afe52022-02-23 16:07:06 -0600289{
290 systemctl stop \
291 obmc-chassis-powered-off@0.target \
292 obmc-host-stop-pre@0.target \
293 obmc-host-stopped@0.target \
294 obmc-host-stopping@0.target \
295 obmc-power-off@0.target \
296 obmc-power-stop-pre@0.target \
297 obmc-power-stop@0.target
298}
299
Patrick Williamsd182bff2022-12-08 06:39:12 -0600300function handle_cmd()
Anthony Wilson79f697e2018-09-13 13:48:52 -0500301{
302 case "$1" in
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500303 chassisoff)
Potin Lai0e044c42022-05-13 23:42:31 +0800304 OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500305 SERVICE=$(mapper get-service $OBJECT)
306 INTERFACE=$STATE_INTERFACE.Chassis
307 PROPERTY=RequestedPowerTransition
308 VALUE=$INTERFACE.Transition.Off
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500309 G_REQUESTED_STATE=$INTERFACE.PowerState.Off
310 G_QUERY="chassisstate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500311 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500312 ;;
313 chassison)
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500314 check_and_warn_boot_block
Potin Lai0e044c42022-05-13 23:42:31 +0800315 OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500316 SERVICE=$(mapper get-service $OBJECT)
317 INTERFACE=$STATE_INTERFACE.Chassis
318 PROPERTY=RequestedPowerTransition
319 VALUE=$INTERFACE.Transition.On
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500320 G_REQUESTED_STATE=$INTERFACE.PowerState.On
321 G_QUERY="chassisstate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500322 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500323 ;;
324 poweroff)
Potin Lai0e044c42022-05-13 23:42:31 +0800325 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500326 SERVICE=$(mapper get-service $OBJECT)
327 INTERFACE=$STATE_INTERFACE.Host
328 PROPERTY=RequestedHostTransition
329 VALUE=$INTERFACE.Transition.Off
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500330 G_REQUESTED_STATE=$INTERFACE.HostState.Off
331 G_QUERY="hoststate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500332 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500333 ;;
334 poweron)
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500335 check_and_warn_boot_block
Potin Lai0e044c42022-05-13 23:42:31 +0800336 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500337 SERVICE=$(mapper get-service $OBJECT)
338 INTERFACE=$STATE_INTERFACE.Host
339 PROPERTY=RequestedHostTransition
340 VALUE=$INTERFACE.Transition.On
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500341 G_REQUESTED_STATE=$INTERFACE.HostState.Running
342 G_QUERY="hoststate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500343 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500344 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500345 bmcstate)
346 OBJECT=$STATE_OBJECT/bmc0
347 SERVICE=$(mapper get-service $OBJECT)
348 INTERFACE=$STATE_INTERFACE.BMC
349 PROPERTY=CurrentBMCState
Patrick Williamsb2398202021-04-13 20:53:26 -0500350 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500351 ;;
352 chassisstate)
Potin Lai0e044c42022-05-13 23:42:31 +0800353 OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID
Anthony Wilson79f697e2018-09-13 13:48:52 -0500354 SERVICE=$(mapper get-service $OBJECT)
355 INTERFACE=$STATE_INTERFACE.Chassis
356 PROPERTY=CurrentPowerState
Patrick Williamsb2398202021-04-13 20:53:26 -0500357 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500358 ;;
359 hoststate)
Potin Lai0e044c42022-05-13 23:42:31 +0800360 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson79f697e2018-09-13 13:48:52 -0500361 SERVICE=$(mapper get-service $OBJECT)
362 INTERFACE=$STATE_INTERFACE.Host
363 PROPERTY=CurrentHostState
Patrick Williamsb2398202021-04-13 20:53:26 -0500364 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500365 ;;
Alexander Filippov86cffd92019-04-03 16:29:57 +0300366 osstate)
Potin Lai0e044c42022-05-13 23:42:31 +0800367 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Alexander Filippov86cffd92019-04-03 16:29:57 +0300368 SERVICE=$(mapper get-service $OBJECT)
369 INTERFACE=$STATE_INTERFACE.OperatingSystem.Status
370 PROPERTY=OperatingSystemState
Patrick Williamsb2398202021-04-13 20:53:26 -0500371 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Alexander Filippov86cffd92019-04-03 16:29:57 +0300372 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500373 state|status)
Alexander Filippov86cffd92019-04-03 16:29:57 +0300374 for query in bmcstate chassisstate hoststate bootprogress osstate
Anthony Wilson79f697e2018-09-13 13:48:52 -0500375 do
376 handle_cmd $query
377 done
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500378 check_and_warn_boot_block
Anthony Wilson79f697e2018-09-13 13:48:52 -0500379 ;;
Anthony Wilson50c5f882018-09-13 14:19:37 -0500380 bootprogress)
Potin Lai0e044c42022-05-13 23:42:31 +0800381 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson50c5f882018-09-13 14:19:37 -0500382 SERVICE=$(mapper get-service $OBJECT)
383 INTERFACE=$STATE_INTERFACE.Boot.Progress
384 PROPERTY=BootProgress
Patrick Williamsb2398202021-04-13 20:53:26 -0500385 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson50c5f882018-09-13 14:19:37 -0500386 ;;
Anthony Wilson0f359832018-09-13 14:28:07 -0500387 power)
388 OBJECT=/org/openbmc/control/power0
389 SERVICE=$(mapper get-service $OBJECT)
390 INTERFACE=org.openbmc.control.Power
Patrick Williamsd182bff2022-12-08 06:39:12 -0600391 for property in pgood state pgood_timeout; do
Anthony Wilson0f359832018-09-13 14:28:07 -0500392 # get_property can potentially return several
393 # different formats of values, so we do the parsing outside
394 # of get_property depending on the query. These queries
395 # return 'i VALUE' formatted strings.
Patrick Williamsd182bff2022-12-08 06:39:12 -0600396 STATE=$(get_property "$SERVICE" "$OBJECT" "$INTERFACE" "$property" | sed 's/i[ ^I]*//')
Patrick Williamsb2398202021-04-13 20:53:26 -0500397 printf "%s = %s\n" $property "$STATE"
Anthony Wilson0f359832018-09-13 14:28:07 -0500398 done
399 ;;
Anthony Wilson189cf242018-10-23 01:18:21 -0500400 chassiskill)
401 /usr/libexec/chassiskill
402 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600403 hostrebootoff)
Potin Lai0e044c42022-05-13 23:42:31 +0800404 OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500405 SERVICE=$(mapper get-service $OBJECT)
406 INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
407 PROPERTY=AutoReboot
408 VALUE=false
Patrick Williamsb2398202021-04-13 20:53:26 -0500409 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500410 ;;
Andrew Geissler3191be82020-10-23 10:45:55 -0500411 hostrebootoffonetime)
Potin Lai0e044c42022-05-13 23:42:31 +0800412 OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot/one_time
Andrew Geissler3191be82020-10-23 10:45:55 -0500413 SERVICE=$(mapper get-service $OBJECT)
414 INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
415 PROPERTY=AutoReboot
416 VALUE=false
Patrick Williamsb2398202021-04-13 20:53:26 -0500417 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Patrick Williamsd182bff2022-12-08 06:39:12 -0600418 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600419 hostrebooton)
Potin Lai0e044c42022-05-13 23:42:31 +0800420 OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500421 SERVICE=$(mapper get-service $OBJECT)
422 INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
423 PROPERTY=AutoReboot
424 VALUE=true
Patrick Williamsb2398202021-04-13 20:53:26 -0500425 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500426 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600427 bmcrebootoff)
428 disable_bmc_reboot
429 ;;
430 bmcrebooton)
431 enable_bmc_reboot
432 ;;
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500433 recoveryoff)
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600434 handle_cmd hostrebootoff
435 handle_cmd bmcrebootoff
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500436 mask_systemd_target $HOST_TIMEOUT_TARGET
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -0600437 mask_systemd_target $HOST_CRASH_TARGET
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500438 ;;
439 recoveryon)
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600440 handle_cmd hostrebooton
441 handle_cmd bmcrebooton
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500442 unmask_systemd_target $HOST_TIMEOUT_TARGET
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -0600443 unmask_systemd_target $HOST_CRASH_TARGET
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500444 ;;
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500445 listbootblock)
446 blockingErrors=$(check_boot_block_errors)
447 if [ -z "$blockingErrors" ]; then
448 echo "No blocking errors present"
449 else
450 echo "$blockingErrors"
451 fi
452 ;;
Andrew Geissler295ee4f2020-05-14 14:14:05 -0500453 listlogs)
454 list_logs
455 ;;
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500456 showlog)
Patrick Williamsb2398202021-04-13 20:53:26 -0500457 show_log "$2"
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500458 ;;
Andrew Geissler42f28982020-05-14 15:12:42 -0500459 deletelogs)
460 delete_logs
461 ;;
Andrew Geisslerad1afe52022-02-23 16:07:06 -0600462 stopofftargets)
463 stop_off_targets
464 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500465 *)
Anthony Wilsonea87db42018-09-26 16:06:38 -0500466 print_usage_err "Invalid command '$1'"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500467 ;;
468 esac
469}
470
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500471shiftcnt=0
Anthony Wilsonea87db42018-09-26 16:06:38 -0500472for arg in "$@"; do
473 case $arg in
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500474 -w|--wait)
475 G_WAIT=30
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500476 shiftcnt=$((shiftcnt+1))
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500477 continue
478 ;;
Anthony Wilsonea87db42018-09-26 16:06:38 -0500479 -h|--help)
480 print_help
481 ;;
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930482 -v|--verbose)
483 G_VERBOSE=y
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500484 shiftcnt=$((shiftcnt+1))
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930485 ;;
Potin Lai0e044c42022-05-13 23:42:31 +0800486 -i=*|--id=*)
487 G_INSTANCE_ID="${arg#*=}"
488 shiftcnt=$((shiftcnt+1))
489 ;;
Anthony Wilsonea87db42018-09-26 16:06:38 -0500490 -*)
491 print_usage_err "Unknown option: $arg"
492 ;;
493 *)
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500494 G_ORIG_CMD=$arg
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500495 # shift out the optional parameters
496 shift $shiftcnt
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500497 # pass all arguments to handle_cmd in case command takes additional
498 # parameters
499 handle_cmd "$@"
Anthony Wilsonea87db42018-09-26 16:06:38 -0500500 break
501 ;;
502 esac
503done