fix: get VM PID early so kill_vm() works reliably

This commit is contained in:
Martin Wimpress 2024-06-30 12:09:04 +01:00 committed by Martin Wimpress
parent 589f2c9a5c
commit 52e50f9815
1 changed files with 12 additions and 12 deletions

View File

@ -1505,7 +1505,7 @@ function vm_boot() {
echo "${QEMU}" "${SHELL_ARGS}" "2>/dev/null" >> "${VMDIR}/${VMNAME}.sh" echo "${QEMU}" "${SHELL_ARGS}" "2>/dev/null" >> "${VMDIR}/${VMNAME}.sh"
sed -i -e 's/ -/ \\\n -/g' "${VMDIR}/${VMNAME}.sh" sed -i -e 's/ -/ \\\n -/g' "${VMDIR}/${VMNAME}.sh"
${QEMU} "${args[@]}" &> "${VMDIR}/${VMNAME}.log" & ${QEMU} "${args[@]}" &> "${VMDIR}/${VMNAME}.log" &
local VM_PID=$! VM_PID=$!
sleep 0.25 sleep 0.25
if kill -0 "${VM_PID}" 2>/dev/null; then if kill -0 "${VM_PID}" 2>/dev/null; then
echo " - Process: Started ${VM} as ${VMNAME} (${VM_PID})" echo " - Process: Started ${VM} as ${VMNAME} (${VM_PID})"
@ -2062,6 +2062,17 @@ if [ -n "${VM}" ] && [ -e "${VM}" ]; then
pushd "${VMPATH}" >/dev/null || exit pushd "${VMPATH}" >/dev/null || exit
fi fi
# Check if VM is already running
VM_PID=""
if [ -r "${VMDIR}/${VMNAME}.pid" ]; then
VM_PID=$(head -n 1 "${VMDIR}/${VMNAME}.pid")
if ! kill -0 "${VM_PID}" > /dev/null 2>&1; then
#VM is not running, cleaning up.
VM_PID=""
rm -f "${VMDIR}/${VMNAME}.pid"
fi
fi
# Iterate over any actions and exit. # Iterate over any actions and exit.
if [ ${#ACTIONS[@]} -ge 1 ]; then if [ ${#ACTIONS[@]} -ge 1 ]; then
for ACTION in "${ACTIONS[@]}"; do for ACTION in "${ACTIONS[@]}"; do
@ -2105,17 +2116,6 @@ tpm_param_check
viewer_param_check viewer_param_check
fileshare_param_check fileshare_param_check
# Check if vm is already run
VM_PID=""
if [ -r "${VMDIR}/${VMNAME}.pid" ]; then
VM_PID=$(head -n 1 "${VMDIR}/${VMNAME}.pid")
if ! kill -0 "${VM_PID}" > /dev/null 2>&1; then
# VM is not running, cleaning up.
VM_PID=""
rm -f "${VMDIR}/${VMNAME}.pid"
fi
fi
if [ -z "${VM_PID}" ]; then if [ -z "${VM_PID}" ]; then
vm_boot vm_boot
start_viewer start_viewer