refactor: improve kill VM logic by using VM_PID

This commit is contained in:
Martin Wimpress 2024-05-11 12:55:43 +01:00 committed by Martin Wimpress
parent 58599a98ab
commit 27ca4a27f0
1 changed files with 8 additions and 9 deletions

View File

@ -1962,21 +1962,20 @@ fi
if [ ${KILL_VM} -eq 1 ]; then
echo "Killing ${VMNAME}"
if [ -r "${VMDIR}/${VMNAME}.pid" ]; then
VM_PID=$(head -c50 "${VMDIR}/${VMNAME}.pid")
if [ -z "${VM_PID}" ]; then
echo " - ${VMNAME} is not running."
rm -f "${VMDIR}/${VMNAME}.pid"
elif [ -n "${VM_PID}" ]; then
if kill -9 "${VM_PID}" > /dev/null 2>&1; then
echo " - ${VMNAME} (${VM_PID}) killed."
rm -f "${VMDIR}/${VMNAME}.pid"
else
echo " - ${VMNAME} (${VM_PID}) was not killed."
fi
elif [ ! -r "${VMDIR}/${VMNAME}.pid" ]; then
echo " - ${VMNAME} has no ${VMDIR}/${VMNAME}.pid"
fi
exit
else
echo " - ERROR! ${VMNAME} with PID ${VM_PID} was not killed."
rm -f "${VMDIR}/${VMNAME}.pid"
exit 1
fi
else
echo " - ERROR! Could not read ${VMDIR}/${VMNAME}.pid."
exit 1
fi
fi
if [ ${DELETE_DISK} -eq 1 ]; then