Files
configpolicy/roles/vmhost/files/vm-autostart.sh
Dustin C. Hatch 2ee86f6344 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.
2025-07-28 18:20:50 -05:00

25 lines
552 B
Bash

#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
if [ ! -r /etc/vm-autostart ]; then
exit 0
fi
virsh connect || exit
while read name args; do
if [ "${name}" = delay ]; then
sleep ${args}
continue
fi
if virsh domuuid "${name}" >/dev/null 2>&1; then
if virsh domid "${name}" | grep -qE '^[0-9]+$'; then
printf 'Domain %s is already running\n' "${name}"
else
virsh start "${name}"
fi
else
printf 'Domain %s does not exist\n' "${name}"
fi
done < /etc/vm-autostart