On Thu, Mar 12, 2026 at 00:51:54 -0000, roy-orbitson--- via Devel wrote: > When libvirt components get updated on a hypervisor, VMs continue > running with obsolete files. Programs like "needrestart" alert one to > this condition with messages like: > > VM guests are running outdated hypervisor (qemu) binaries on this host: > 'bazquux' with pid 1234 > > Normal restarting of a VM (from within or with `virsh reboot ...`) does > not resolve it because it's 'warm'; VMs must be completely shut down > then started again to utilise the updates. Afaik, to do so reliably, in > a way that minimises downtime, requires scripts like this: > > (d=bazquux; virsh shutdown --domain "$d" && until LC_ALL=C LANG=C virsh > domstate --domain "$d" | grep -Fi 'shut off' &> /dev/null; do echo ...; sleep > 1; done && virsh start --domain "$d") > > Adding a timeout complicates that further. Options for this logic to > be performed by virsh would be beneficial, as a single operation: > > virsh reboot --domain bazquux --cold > > And by allowing poweroff to wait: > > (d=bazquux; virsh shutdown --domain "$d" --synchronous && virsh start > --domain "$d")
Aside from the complexities Michal pointed out, I've added 'virsh await' some time ago. It allows you to wait for VM to reach a "condition", one of the conditions I've added would allow you to do what you want: virsh shutdown $DOM; virsh await --condition domain-inactive $DOM 'virsh await' terminates only after $DOM is in inactive state. It also supports '--timeout' to break out from deadlocks if needed.
