Sharing this as it might help someone playing around with kvm/qemu
I've got a pretty hefty lenovo thinkstation as a home lab
running fedora 41 with a lot of home grown scripts related to my current and past work with Red Hat
e.g. scripts to start up several vms at once (either a ceph cluster or pacemaker), etc ... add a raw disk as a shared disk between vms...
anyway, been messing around with some scripting in rc.local only to finally realize that libvirtd shuts down before rc.local gets run on a shutdown and that renders my script useless. I am aware with the autostart option, but don't really want to autostart everything.
anyway, the answer was the built in libvirt-guests.service
sudo systemctl enable --now libvirt-guests.service
~~~
$ cat /etc/sysconfig/libvirt-guests
ON_BOOT=start
ON_SHUTDOWN=suspend
~~
And then that takes care of whatever is running at shutdown and restores it afterwards.
~~~
Jun 20 13:43:01 lab libvirt-guests.sh[3396]: Running guests on default URI:
Jun 20 13:43:01 lab libvirt-guests.sh[3351]: rhel79-gfs-node1, rhel79-gfs-node2, rhel84-gfs-node1, rhel84-gfs-node2
Jun 20 13:43:01 lab libvirt-guests.sh[3500]: Suspending guests on default URI...
Jun 20 13:43:01 lab libvirt-guests.sh[3351]: Suspending rhel79-gfs-node1: ...
Jun 20 13:43:04 lab libvirt-guests.sh[3351]: Suspending rhel79-gfs-node1: done
Jun 20 13:43:04 lab libvirt-guests.sh[3351]: Suspending rhel79-gfs-node2: ...
Jun 20 13:43:07 lab libvirt-guests.sh[3351]: Suspending rhel79-gfs-node2: done
Jun 20 13:43:07 lab libvirt-guests.sh[3351]: Suspending rhel84-gfs-node1: ...
Jun 20 13:43:11 lab libvirt-guests.sh[3351]: Suspending rhel84-gfs-node1: done
Jun 20 13:43:11 lab libvirt-guests.sh[3351]: Suspending rhel84-gfs-node2: ...
Jun 20 13:43:15 lab libvirt-guests.sh[3351]: Suspending rhel84-gfs-node2: done
Jun 20 13:43:15 lab systemd[1]: libvirt-guests.service: Deactivated successfully.
Jun 20 13:43:15 lab systemd[1]: Stopped libvirt-guests.service - libvirt guests suspend/resume service.
-- Boot 19096a0e8e3941d9bd8cf112b16b6ebf --
Jun 20 13:45:19 lab systemd[1]: Starting libvirt-guests.service - libvirt guests suspend/resume service...
Jun 20 13:46:03 lab libvirt-guests.sh[2091]: Resuming guests on default URI...
Jun 20 13:46:08 lab libvirt-guests.sh[2097]: Resuming guest rhel79-gfs-node1:
Jun 20 13:46:08 lab libvirt-guests.sh[2507]: done
Jun 20 13:46:11 lab libvirt-guests.sh[2512]: Resuming guest rhel79-gfs-node2:
Jun 20 13:46:11 lab libvirt-guests.sh[2518]: error: Failed to start domain 'rhel79-gfs-node2'
Jun 20 13:46:11 lab libvirt-guests.sh[2518]: error: operation failed: domain is not running
Jun 20 13:46:14 lab libvirt-guests.sh[2582]: Resuming guest rhel84-gfs-node1:
Jun 20 13:46:14 lab libvirt-guests.sh[2729]: done
Jun 20 13:46:18 lab libvirt-guests.sh[2734]: Resuming guest rhel84-gfs-node2:
Jun 20 13:46:18 lab libvirt-guests.sh[2840]: done
Jun 20 13:46:18 lab systemd[1]: libvirt-guests.service: Main process exited, code=exited, status=1/FAILURE
~~~
if this helps anyone :)
~George