From 2ee86f6344a50fe383b7acccd7f83d3c9a6edd3e Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 28 Jul 2025 18:20:50 -0500 Subject: [PATCH] r/vmhost: Retry vm-autostart if libvirt is down If the _libvirt_ daemon has not fully started by the time `vm-autostart` runs, we want it to fail and try again shortly. To allow this, we first attempt to connect to the _libvirt_ socket, and if that fails, stop immediately and try again in a second. This way, the first few VMs don't get skipped with the assumption that they're missing, just because the daemon wasn't ready yet. --- roles/vmhost/files/vm-autostart.service | 3 +++ roles/vmhost/files/vm-autostart.sh | 2 ++ 2 files changed, 5 insertions(+) diff --git a/roles/vmhost/files/vm-autostart.service b/roles/vmhost/files/vm-autostart.service index 1497cd1..712df64 100644 --- a/roles/vmhost/files/vm-autostart.service +++ b/roles/vmhost/files/vm-autostart.service @@ -4,6 +4,8 @@ After=libvirt.service After=network-online.target Wants=network-online.target RequiresMountsFor=/var/lib/libvirt/images +StartLimitInterval=1s +StartLimitBurst=1 [Service] Type=oneshot @@ -11,6 +13,7 @@ RemainAfterExit=yes Environment=LIBVIRT_DEFAULT_URI=qemu:///system ExecStart=/usr/local/libexec/vm-autostart.sh Restart=on-failure +RestartSec=1 CapabilityBoundingSet= DeviceAllow= diff --git a/roles/vmhost/files/vm-autostart.sh b/roles/vmhost/files/vm-autostart.sh index be8be11..ef99ef4 100644 --- a/roles/vmhost/files/vm-autostart.sh +++ b/roles/vmhost/files/vm-autostart.sh @@ -5,6 +5,8 @@ if [ ! -r /etc/vm-autostart ]; then exit 0 fi +virsh connect || exit + while read name args; do if [ "${name}" = delay ]; then sleep ${args}