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,6 +84,12 @@ function vm_boot() {
exit 1
fi
elif [ -e ${disk_img} ]; then
# 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
disk_curr_size=$(stat -c%s "${disk_img}")
if [ ${disk_curr_size} -le ${disk_min_size} ]; then
echo " Looks unused, booting from ${iso}"
@ -93,6 +99,7 @@ function vm_boot() {
iso=""
fi
fi
fi
local cores="1"
local allcores=$(nproc --all)