1*128ea8e3SAndrew Geissler#!/bin/bash -e 2*128ea8e3SAndrew Geissler# A script which is called in a host-reboot path to check the host reboot count 3*128ea8e3SAndrew Geissler# and either initiate the host firmware boot, or move it to the quiesce state 4*128ea8e3SAndrew Geissler# (if the reboot count has been reached) 5*128ea8e3SAndrew Geissler 6*128ea8e3SAndrew Geissler# This script has a single required parameter, the instance number of the 7*128ea8e3SAndrew Geissler# host that is being rebooted (or quiesced) 8*128ea8e3SAndrew Geissler 9*128ea8e3SAndrew Geisslerset -euo pipefail 10*128ea8e3SAndrew Geissler 11*128ea8e3SAndrew Geisslerget_reboot_count() 12*128ea8e3SAndrew Geissler{ 13*128ea8e3SAndrew Geissler busctl get-property xyz.openbmc_project.State.Host \ 14*128ea8e3SAndrew Geissler /xyz/openbmc_project/state/host0 \ 15*128ea8e3SAndrew Geissler xyz.openbmc_project.Control.Boot.RebootAttempts AttemptsLeft \ 16*128ea8e3SAndrew Geissler | cut -d ' ' -f2 17*128ea8e3SAndrew Geissler} 18*128ea8e3SAndrew Geissler 19*128ea8e3SAndrew Geissler# host instance id is input parameter to function 20*128ea8e3SAndrew Geisslerhost_quiesce() 21*128ea8e3SAndrew Geissler{ 22*128ea8e3SAndrew Geissler systemctl start obmc-host-quiesce@"$1".target 23*128ea8e3SAndrew Geissler} 24*128ea8e3SAndrew Geissler 25*128ea8e3SAndrew Geissler# host instance id is input parameter to function 26*128ea8e3SAndrew Geisslerhost_reboot() 27*128ea8e3SAndrew Geissler{ 28*128ea8e3SAndrew Geissler systemctl start obmc-host-startmin@"$1".target 29*128ea8e3SAndrew Geissler} 30*128ea8e3SAndrew Geissler 31*128ea8e3SAndrew Geissler# This service is run as a part of a systemd target to reboot the host 32*128ea8e3SAndrew Geissler# As such, it has to first shutdown the host, and then reboot it. Due to 33*128ea8e3SAndrew Geissler# systemd complexities with Conflicts statements between the targets to 34*128ea8e3SAndrew Geissler# shutdown and to boot, need to start off by sleeping 5 seconds to ensure 35*128ea8e3SAndrew Geissler# the shutdown path has completed before starting the boot (or quiesce) 36*128ea8e3SAndrew Geisslersleep 5 37*128ea8e3SAndrew Geissler 38*128ea8e3SAndrew Geisslerhost_instance=$1 39*128ea8e3SAndrew Geissler 40*128ea8e3SAndrew Geisslerreboot_count=$(get_reboot_count) 41*128ea8e3SAndrew Geisslerif [ "$reboot_count" -eq 0 ]; then 42*128ea8e3SAndrew Geissler echo "reboot count is 0, go to host quiesce" 43*128ea8e3SAndrew Geissler host_quiesce "$host_instance" 44*128ea8e3SAndrew Geisslerelse 45*128ea8e3SAndrew Geissler echo "reboot count is $reboot_count so reboot host" 46*128ea8e3SAndrew Geissler host_reboot "$host_instance" 47*128ea8e3SAndrew Geisslerfi 48