blob: 3fc0ded8f22e7a81561bffb2c49949d3b240e6b5 [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 Geissler42f28982020-05-14 15:12:42 -05007bmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs"
Anthony Wilson0f359832018-09-13 14:28:07 -05008
Andrew Jeffery60c3ac82019-10-02 09:29:29 +09309USAGE="Usage: obmcutil [-h] [--wait] [--verbose]
Anthony Wilson0f359832018-09-13 14:28:07 -050010 {$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=
Anthony Wilsonacf54d02018-09-20 15:19:28 -050041
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050042print_help ()
43{
44 echo "$USAGE"
45 echo ""
46 echo "positional arguments:"
Anthony Wilson0f359832018-09-13 14:28:07 -050047 echo " {$OPTS}"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050048 echo ""
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050049 echo "Examples:"
50 echo ""
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060051 echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state"
Andrew Geissler3191be82020-10-23 10:45:55 -050052 echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from"
53 echo " Quiesce state for a single boot"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060054 echo "obmcutil hostrebooton Enable auto reboot of Host from Quiesce state"
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050055 echo ""
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060056 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 Subbanna7a787dd2019-10-31 06:02:31 -050064 echo ""
Andrew Geissler3b7b5612020-05-14 10:45:29 -050065 echo "obmcutil listbootblock Check for and list any errors blocking the boot"
66 echo " of the system"
67 echo ""
Andrew Geissler295ee4f2020-05-14 14:14:05 -050068 echo "obmcutil listlogs List all phosphor-logging entries on the"
69 echo " system"
70 echo ""
Andrew Geisslerd8c63202020-05-14 15:06:31 -050071 echo "obmcutil showlog <log> Display details of input log. Format of <log>"
72 echo " should match listlogs output"
73 echo ""
Andrew Geissler42f28982020-05-14 15:12:42 -050074 echo "obmcutil deletelogs Delete all phosphor-logging entries from"
75 echo " system"
76 echo ""
Andrew Geisslerd8779cd2020-06-11 10:48:40 -050077 echo "optional arguments (must precede the positional options above):"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050078 echo " -h, --help show this help message and exit"
Anthony Wilsonacf54d02018-09-20 15:19:28 -050079 echo " -w, --wait block until state transition succeeds or fails"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093080 echo " -v, --verbose print the journal to stdout if --wait is supplied"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050081 exit 0
82}
83
Anthony Wilsonacf54d02018-09-20 15:19:28 -050084run_timeout ()
85{
86 local timeout="$1"; shift
Patrick Williamsb2398202021-04-13 20:53:26 -050087 local cmd="$*"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093088 local verbose_child=
89
Andrew Jeffery2869a922019-10-18 14:42:34 +103090 if [ -n "$G_VERBOSE" ]; then
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093091 journalctl -f &
92 verbose_child=$!
93 fi
Anthony Wilsonacf54d02018-09-20 15:19:28 -050094
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 Williamsb2398202021-04-13 20:53:26 -0500101 while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500102 sleep 1
103 done
104 ) &
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930105 wait_child=$!
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500106
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 Williamsb2398202021-04-13 20:53:26 -0500113 sleep "$timeout"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930114 kill $wait_child
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500115 ) > /dev/null 2>&1 &
116
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930117 if ! wait $wait_child; then
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500118 echo "Unable to confirm '$G_ORIG_CMD' success" \
119 "within timeout period (${timeout}s)"
120 fi
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930121
Andrew Jeffery8be70292019-11-01 08:56:49 +1030122 if [ -n "$verbose_child" ]; then
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930123 kill $verbose_child
124 fi
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500125}
126
127run_cmd ()
128{
Patrick Williamsb2398202021-04-13 20:53:26 -0500129 local cmd="$*";
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500130
131 if [ -n "$G_WAIT" ]; then
Patrick Williamsb2398202021-04-13 20:53:26 -0500132 run_timeout "$G_WAIT" "$cmd"
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500133 else
134 $cmd
135 fi
136}
137
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500138set_property ()
139{
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500140 run_cmd busctl set-property "$@"
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500141}
142
Anthony Wilson79f697e2018-09-13 13:48:52 -0500143get_property ()
144{
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500145 G_WAIT=""
146 run_cmd busctl get-property "$@"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500147}
148
149state_query ()
150{
Patrick Williamsb2398202021-04-13 20:53:26 -0500151 local state
152 state=$(get_property "$@" | cut -d '"' -f2)
153 printf "%-20s: %s\n" "$4" "$state"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500154}
155
Anthony Wilsonea87db42018-09-26 16:06:38 -0500156print_usage_err ()
157{
158 echo "ERROR: $1" >&2
159 echo "$USAGE"
160 exit 1
161}
162
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500163mask_systemd_target ()
164{
Patrick Williamsb2398202021-04-13 20:53:26 -0500165 target="$*"
166 systemctl mask "$target"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500167}
168
169unmask_systemd_target ()
170{
Patrick Williamsb2398202021-04-13 20:53:26 -0500171 target="$*"
172 systemctl unmask "$target"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500173}
174
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600175disable_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 Williamsb2398202021-04-13 20:53:26 -0500182 mkdir -p "${dir}${unit}.target.d"
183 echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600184 done
185}
186
187enable_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 Williamsb2398202021-04-13 20:53:26 -0500194 rm -rf "${dir}${unit}.target.d/${file}"
195 rm -rf "${dir}${unit}.target.d"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600196 done
197}
198
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500199# will write blocking errors to stdout
200check_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 Williamsb2398202021-04-13 20:53:26 -0500214 # shellcheck disable=SC2001
215 subtree="$(echo "$subtree" | sed 's/\"//g')"
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500216
217 for entry in $subtree; do
218 if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then
Patrick Williamsb2398202021-04-13 20:53:26 -0500219 blockArray+=( "$entry" )
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500220 fi
221 done
222
223 # now find associated error log for each boot block error
224 for berror in "${blockArray[@]}"; do
Patrick Williamsb2398202021-04-13 20:53:26 -0500225 assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500226 org.freedesktop.DBus.Properties Get \
227 ss xyz.openbmc_project.Association.Definitions Associations)"
228
229 # remove quotation marks
Patrick Williamsb2398202021-04-13 20:53:26 -0500230 # shellcheck disable=SC2001
231 assocs="$(echo "$assocs" | sed 's/\"//g')"
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500232
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 Geisslerdeb6bb42020-05-14 13:44:57 -0500241# helper function to check for boot block errors and notify user
242check_and_warn_boot_block()
243{
244 blockingErrors=$(check_boot_block_errors)
Patrick Williamsb2398202021-04-13 20:53:26 -0500245 if [ -n "$blockingErrors" ]; then
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500246 echo !!!!!!!!!!
247 echo "WARNING! System has blocking errors that will prevent boot"
248 echo "$blockingErrors"
249 echo !!!!!!!!!!
250 fi
251}
252
Andrew Geissler295ee4f2020-05-14 14:14:05 -0500253# list all phosphor-logging entries
254list_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 Geisslerd8c63202020-05-14 15:06:31 -0500265# display input log details
266show_log()
267{
268 busctl -j call xyz.openbmc_project.Logging \
Patrick Williamsb2398202021-04-13 20:53:26 -0500269 "$1" \
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500270 org.freedesktop.DBus.Properties \
271 GetAll s xyz.openbmc_project.Logging.Entry
272}
273
Andrew Geissler42f28982020-05-14 15:12:42 -0500274# delete all phosphor-logging entries
275delete_logs()
276{
277 busctl call xyz.openbmc_project.Logging \
278 /xyz/openbmc_project/logging \
279 xyz.openbmc_project.Collection.DeleteAll DeleteAll
280}
281
Anthony Wilson79f697e2018-09-13 13:48:52 -0500282handle_cmd ()
283{
284 case "$1" in
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500285 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 Wilsonacf54d02018-09-20 15:19:28 -0500291 G_REQUESTED_STATE=$INTERFACE.PowerState.Off
292 G_QUERY="chassisstate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500293 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500294 ;;
295 chassison)
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500296 check_and_warn_boot_block
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500297 OBJECT=$STATE_OBJECT/chassis0
298 SERVICE=$(mapper get-service $OBJECT)
299 INTERFACE=$STATE_INTERFACE.Chassis
300 PROPERTY=RequestedPowerTransition
301 VALUE=$INTERFACE.Transition.On
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500302 G_REQUESTED_STATE=$INTERFACE.PowerState.On
303 G_QUERY="chassisstate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500304 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500305 ;;
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 Wilsonacf54d02018-09-20 15:19:28 -0500312 G_REQUESTED_STATE=$INTERFACE.HostState.Off
313 G_QUERY="hoststate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500314 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500315 ;;
316 poweron)
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500317 check_and_warn_boot_block
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500318 OBJECT=$STATE_OBJECT/host0
319 SERVICE=$(mapper get-service $OBJECT)
320 INTERFACE=$STATE_INTERFACE.Host
321 PROPERTY=RequestedHostTransition
322 VALUE=$INTERFACE.Transition.On
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500323 G_REQUESTED_STATE=$INTERFACE.HostState.Running
324 G_QUERY="hoststate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500325 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500326 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500327 bmcstate)
328 OBJECT=$STATE_OBJECT/bmc0
329 SERVICE=$(mapper get-service $OBJECT)
330 INTERFACE=$STATE_INTERFACE.BMC
331 PROPERTY=CurrentBMCState
Patrick Williamsb2398202021-04-13 20:53:26 -0500332 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500333 ;;
334 chassisstate)
335 OBJECT=$STATE_OBJECT/chassis0
336 SERVICE=$(mapper get-service $OBJECT)
337 INTERFACE=$STATE_INTERFACE.Chassis
338 PROPERTY=CurrentPowerState
Patrick Williamsb2398202021-04-13 20:53:26 -0500339 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500340 ;;
341 hoststate)
342 OBJECT=$STATE_OBJECT/host0
343 SERVICE=$(mapper get-service $OBJECT)
344 INTERFACE=$STATE_INTERFACE.Host
345 PROPERTY=CurrentHostState
Patrick Williamsb2398202021-04-13 20:53:26 -0500346 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500347 ;;
Alexander Filippov86cffd92019-04-03 16:29:57 +0300348 osstate)
349 OBJECT=$STATE_OBJECT/host0
350 SERVICE=$(mapper get-service $OBJECT)
351 INTERFACE=$STATE_INTERFACE.OperatingSystem.Status
352 PROPERTY=OperatingSystemState
Patrick Williamsb2398202021-04-13 20:53:26 -0500353 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Alexander Filippov86cffd92019-04-03 16:29:57 +0300354 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500355 state|status)
Alexander Filippov86cffd92019-04-03 16:29:57 +0300356 for query in bmcstate chassisstate hoststate bootprogress osstate
Anthony Wilson79f697e2018-09-13 13:48:52 -0500357 do
358 handle_cmd $query
359 done
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500360 check_and_warn_boot_block
Anthony Wilson79f697e2018-09-13 13:48:52 -0500361 ;;
Anthony Wilson50c5f882018-09-13 14:19:37 -0500362 bootprogress)
363 OBJECT=$STATE_OBJECT/host0
364 SERVICE=$(mapper get-service $OBJECT)
365 INTERFACE=$STATE_INTERFACE.Boot.Progress
366 PROPERTY=BootProgress
Patrick Williamsb2398202021-04-13 20:53:26 -0500367 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson50c5f882018-09-13 14:19:37 -0500368 ;;
Anthony Wilson0f359832018-09-13 14:28:07 -0500369 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 Williamsb2398202021-04-13 20:53:26 -0500379 STATE=$(get_property "$SERVICE" $OBJECT $INTERFACE $property \
Anthony Wilson0f359832018-09-13 14:28:07 -0500380 | sed 's/i[ ^I]*//')
Patrick Williamsb2398202021-04-13 20:53:26 -0500381 printf "%s = %s\n" $property "$STATE"
Anthony Wilson0f359832018-09-13 14:28:07 -0500382 done
383 ;;
Anthony Wilson189cf242018-10-23 01:18:21 -0500384 chassiskill)
385 /usr/libexec/chassiskill
386 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600387 hostrebootoff)
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500388 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 Williamsb2398202021-04-13 20:53:26 -0500393 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500394 ;;
Andrew Geissler3191be82020-10-23 10:45:55 -0500395 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 Williamsb2398202021-04-13 20:53:26 -0500401 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Andrew Geissler3191be82020-10-23 10:45:55 -0500402 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600403 hostrebooton)
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500404 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 Williamsb2398202021-04-13 20:53:26 -0500409 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500410 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600411 bmcrebootoff)
412 disable_bmc_reboot
413 ;;
414 bmcrebooton)
415 enable_bmc_reboot
416 ;;
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500417 recoveryoff)
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600418 handle_cmd hostrebootoff
419 handle_cmd bmcrebootoff
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500420 mask_systemd_target $HOST_TIMEOUT_TARGET
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -0600421 mask_systemd_target $HOST_CRASH_TARGET
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500422 ;;
423 recoveryon)
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600424 handle_cmd hostrebooton
425 handle_cmd bmcrebooton
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500426 unmask_systemd_target $HOST_TIMEOUT_TARGET
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -0600427 unmask_systemd_target $HOST_CRASH_TARGET
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500428 ;;
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500429 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 Geissler295ee4f2020-05-14 14:14:05 -0500437 listlogs)
438 list_logs
439 ;;
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500440 showlog)
Patrick Williamsb2398202021-04-13 20:53:26 -0500441 show_log "$2"
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500442 ;;
Andrew Geissler42f28982020-05-14 15:12:42 -0500443 deletelogs)
444 delete_logs
445 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500446 *)
Anthony Wilsonea87db42018-09-26 16:06:38 -0500447 print_usage_err "Invalid command '$1'"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500448 ;;
449 esac
450}
451
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500452shiftcnt=0
Anthony Wilsonea87db42018-09-26 16:06:38 -0500453for arg in "$@"; do
454 case $arg in
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500455 -w|--wait)
456 G_WAIT=30
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500457 shiftcnt=$((shiftcnt+1))
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500458 continue
459 ;;
Anthony Wilsonea87db42018-09-26 16:06:38 -0500460 -h|--help)
461 print_help
462 ;;
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930463 -v|--verbose)
464 G_VERBOSE=y
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500465 shiftcnt=$((shiftcnt+1))
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930466 ;;
Anthony Wilsonea87db42018-09-26 16:06:38 -0500467 -*)
468 print_usage_err "Unknown option: $arg"
469 ;;
470 *)
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500471 G_ORIG_CMD=$arg
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500472 # shift out the optional parameters
473 shift $shiftcnt
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500474 # pass all arguments to handle_cmd in case command takes additional
475 # parameters
476 handle_cmd "$@"
Anthony Wilsonea87db42018-09-26 16:06:38 -0500477 break
478 ;;
479 esac
480done