blob: e75c681a015d56272c5267881c0af0df28141c62 [file] [log] [blame]
Andrew Geissler128ea8e2022-06-22 12:28:15 -04001#!/bin/bash -e
2# A script which is called in a host-reboot path to check the host reboot count
3# and either initiate the host firmware boot, or move it to the quiesce state
4# (if the reboot count has been reached)
5
6# This script has a single required parameter, the instance number of the
7# host that is being rebooted (or quiesced)
8
9set -euo pipefail
10
Patrick Williamsd182bff2022-12-08 06:39:12 -060011function get_reboot_count()
Andrew Geissler128ea8e2022-06-22 12:28:15 -040012{
Potin Lai26854612022-08-19 09:24:45 +000013 busctl get-property xyz.openbmc_project.State.Host"$1" \
14 /xyz/openbmc_project/state/host"$1" \
Andrew Geissler128ea8e2022-06-22 12:28:15 -040015 xyz.openbmc_project.Control.Boot.RebootAttempts AttemptsLeft \
16 | cut -d ' ' -f2
17}
18
Patrick Williamsd182bff2022-12-08 06:39:12 -060019function get_restart_cause()
Andrew Geissler55324b42022-10-27 09:19:19 -050020{
21 busctl get-property xyz.openbmc_project.State.Host"$1" \
22 /xyz/openbmc_project/state/host"$1" \
23 xyz.openbmc_project.State.Host RestartCause \
24 | cut -d '"' -f2
25}
26
Andrew Geissler128ea8e2022-06-22 12:28:15 -040027# host instance id is input parameter to function
Patrick Williamsd182bff2022-12-08 06:39:12 -060028function host_quiesce()
Andrew Geissler128ea8e2022-06-22 12:28:15 -040029{
30 systemctl start obmc-host-quiesce@"$1".target
31}
32
33# host instance id is input parameter to function
Patrick Williamsd182bff2022-12-08 06:39:12 -060034function host_reboot()
Andrew Geissler128ea8e2022-06-22 12:28:15 -040035{
36 systemctl start obmc-host-startmin@"$1".target
37}
38
39# This service is run as a part of a systemd target to reboot the host
40# As such, it has to first shutdown the host, and then reboot it. Due to
41# systemd complexities with Conflicts statements between the targets to
42# shutdown and to boot, need to start off by sleeping 5 seconds to ensure
43# the shutdown path has completed before starting the boot (or quiesce)
44sleep 5
45
46host_instance=$1
47
Andrew Geissler55324b42022-10-27 09:19:19 -050048# Normally the standard power on path will determine if the system has reached
49# its reboot count and halt in Quiesce if so. But in the host-crash path this
50# standard path is not utilized, as it goes only through systemd targets. To
51# ensure the system does not end up in an endless reboot loop, put host into
52# Quiesce if reboot count is exhausted and the reason for the reboot was a
53# HostCrash
Potin Lai26854612022-08-19 09:24:45 +000054reboot_count=$(get_reboot_count "$host_instance")
Andrew Geissler55324b42022-10-27 09:19:19 -050055restart_cause=$(get_restart_cause "$host_instance")
56if [ "$reboot_count" -eq 0 ] && \
Patrick Williamsd182bff2022-12-08 06:39:12 -060057 [ "$restart_cause" == "xyz.openbmc_project.State.Host.RestartCause.HostCrash" ];
Andrew Geissler55324b42022-10-27 09:19:19 -050058then
59 echo "reboot count is 0 and host crashed, go to host quiesce"
Andrew Geissler128ea8e2022-06-22 12:28:15 -040060 host_quiesce "$host_instance"
61else
Andrew Geissler55324b42022-10-27 09:19:19 -050062 echo "reboot count ($reboot_count) is greater then 0 or host did not" \
Patrick Williamsd182bff2022-12-08 06:39:12 -060063 "crash so reboot host"
Andrew Geissler128ea8e2022-06-22 12:28:15 -040064 host_reboot "$host_instance"
65fi