Prevent starting multiple instances of the same VM

This commit is contained in:
Martin Wimpress 2020-03-20 18:16:51 +00:00
parent d48dc74e95
commit fb627583b9
No known key found for this signature in database
GPG key ID: 61DF940515E06DA3

View file

@ -84,13 +84,20 @@ function vm_boot() {
exit 1
fi
elif [ -e ${disk_img} ]; then
disk_curr_size=$(stat -c%s "${disk_img}")
if [ ${disk_curr_size} -le ${disk_min_size} ]; then
echo " Looks unused, booting from ${iso}"
# Check there isn't already a process attached to the disk image.
QEMU_LOCK_TEST=$(${QEMU_IMG} info ${disk_img} 2>/dev/null)
if [ $? -ne 0 ]; then
echo " Failed to get "write" lock. Is another process using the disk?"
exit 1
else
# If there is a disk image, that appears to have an install
# then do not boot from the iso
iso=""
disk_curr_size=$(stat -c%s "${disk_img}")
if [ ${disk_curr_size} -le ${disk_min_size} ]; then
echo " Looks unused, booting from ${iso}"
else
# If there is a disk image, that appears to have an install
# then do not boot from the iso
iso=""
fi
fi
fi