r/vmhost: Add autostart script

*libvirt*'s native autostart functionality does not work well for
machines that migrate between hosts.  Machines lose their auto-start
flag when they are migrated, and the flag is not restored if they are
migrated back.  This makes the feature pretty useless for us.

To work around this limitation, I've added a script that is run during
boot that will start the machines listed in `/etc/vm-autostart`, if they
exist.  That file can also insert a delay between starting two machines,
which may be useful to allow services to fully start on one machine
before starting another that may depend on them.
This commit is contained in:
2022-08-20 21:15:31 -05:00
parent a433d1b01b
commit 0cd58564c9
6 changed files with 114 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
if [ ! -r /etc/vm-autostart ]; then
exit 0
fi
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