Andrew Geissler | 128ea8e | 2022-06-22 12:28:15 -0400 | [diff] [blame] | 1 | #!/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 | |
| 9 | set -euo pipefail |
| 10 | |
| 11 | get_reboot_count() |
| 12 | { |
| 13 | busctl get-property xyz.openbmc_project.State.Host \ |
| 14 | /xyz/openbmc_project/state/host0 \ |
| 15 | xyz.openbmc_project.Control.Boot.RebootAttempts AttemptsLeft \ |
| 16 | | cut -d ' ' -f2 |
| 17 | } |
| 18 | |
| 19 | # host instance id is input parameter to function |
| 20 | host_quiesce() |
| 21 | { |
| 22 | systemctl start obmc-host-quiesce@"$1".target |
| 23 | } |
| 24 | |
| 25 | # host instance id is input parameter to function |
| 26 | host_reboot() |
| 27 | { |
| 28 | systemctl start obmc-host-startmin@"$1".target |
| 29 | } |
| 30 | |
| 31 | # This service is run as a part of a systemd target to reboot the host |
| 32 | # As such, it has to first shutdown the host, and then reboot it. Due to |
| 33 | # systemd complexities with Conflicts statements between the targets to |
| 34 | # shutdown and to boot, need to start off by sleeping 5 seconds to ensure |
| 35 | # the shutdown path has completed before starting the boot (or quiesce) |
| 36 | sleep 5 |
| 37 | |
| 38 | host_instance=$1 |
| 39 | |
| 40 | reboot_count=$(get_reboot_count) |
| 41 | if [ "$reboot_count" -eq 0 ]; then |
| 42 | echo "reboot count is 0, go to host quiesce" |
| 43 | host_quiesce "$host_instance" |
| 44 | else |
| 45 | echo "reboot count is $reboot_count so reboot host" |
| 46 | host_reboot "$host_instance" |
| 47 | fi |