1128ea8e3SAndrew Geissler#!/bin/bash -e 2128ea8e3SAndrew Geissler# A script which is called in a host-reboot path to check the host reboot count 3128ea8e3SAndrew Geissler# and either initiate the host firmware boot, or move it to the quiesce state 4128ea8e3SAndrew Geissler# (if the reboot count has been reached) 5128ea8e3SAndrew Geissler 6128ea8e3SAndrew Geissler# This script has a single required parameter, the instance number of the 7128ea8e3SAndrew Geissler# host that is being rebooted (or quiesced) 8128ea8e3SAndrew Geissler 9128ea8e3SAndrew Geisslerset -euo pipefail 10128ea8e3SAndrew Geissler 11128ea8e3SAndrew Geisslerget_reboot_count() 12128ea8e3SAndrew Geissler{ 13*26854617SPotin Lai busctl get-property xyz.openbmc_project.State.Host"$1" \ 14*26854617SPotin Lai /xyz/openbmc_project/state/host"$1" \ 15128ea8e3SAndrew Geissler xyz.openbmc_project.Control.Boot.RebootAttempts AttemptsLeft \ 16128ea8e3SAndrew Geissler | cut -d ' ' -f2 17128ea8e3SAndrew Geissler} 18128ea8e3SAndrew Geissler 19128ea8e3SAndrew Geissler# host instance id is input parameter to function 20128ea8e3SAndrew Geisslerhost_quiesce() 21128ea8e3SAndrew Geissler{ 22128ea8e3SAndrew Geissler systemctl start obmc-host-quiesce@"$1".target 23128ea8e3SAndrew Geissler} 24128ea8e3SAndrew Geissler 25128ea8e3SAndrew Geissler# host instance id is input parameter to function 26128ea8e3SAndrew Geisslerhost_reboot() 27128ea8e3SAndrew Geissler{ 28128ea8e3SAndrew Geissler systemctl start obmc-host-startmin@"$1".target 29128ea8e3SAndrew Geissler} 30128ea8e3SAndrew Geissler 31128ea8e3SAndrew Geissler# This service is run as a part of a systemd target to reboot the host 32128ea8e3SAndrew Geissler# As such, it has to first shutdown the host, and then reboot it. Due to 33128ea8e3SAndrew Geissler# systemd complexities with Conflicts statements between the targets to 34128ea8e3SAndrew Geissler# shutdown and to boot, need to start off by sleeping 5 seconds to ensure 35128ea8e3SAndrew Geissler# the shutdown path has completed before starting the boot (or quiesce) 36128ea8e3SAndrew Geisslersleep 5 37128ea8e3SAndrew Geissler 38128ea8e3SAndrew Geisslerhost_instance=$1 39128ea8e3SAndrew Geissler 40*26854617SPotin Laireboot_count=$(get_reboot_count "$host_instance") 41128ea8e3SAndrew Geisslerif [ "$reboot_count" -eq 0 ]; then 42128ea8e3SAndrew Geissler echo "reboot count is 0, go to host quiesce" 43128ea8e3SAndrew Geissler host_quiesce "$host_instance" 44128ea8e3SAndrew Geisslerelse 45128ea8e3SAndrew Geissler echo "reboot count is $reboot_count so reboot host" 46128ea8e3SAndrew Geissler host_reboot "$host_instance" 47128ea8e3SAndrew Geisslerfi 48