@@ -62,14 +62,16 @@ echo " Console socket: ${CONSOLE_SOCK}"
6262
6363source " ${SCRIPT_DIR} /ovmf.sh"
6464
65+ READYZ_TIMEOUT=" ${READYZ_TIMEOUT:- 300} "
66+
6567echo " start.sh: launching qemu-system-x86_64..."
6668echo " start.sh: QEMU_ACCEL_ARGS=${QEMU_ACCEL_ARGS[*]} "
6769echo " start.sh: VM_IMAGE=${VM_IMAGE} ($( du -h " ${VM_IMAGE} " | cut -f1) )"
6870echo " start.sh: VM_DATA_DISK=${VM_DATA_DISK} "
6971
70- # exec replaces this shell with QEMU so the playground can track and kill
71- # the process directly. QEMU runs in the foreground (no -daemonize).
72- exec qemu-system-x86_64 \
72+ # QEMU daemonizes (forks into background)
73+ qemu-system-x86_64 \
74+ -daemonize \
7375 -pidfile " ${PIDFILE} " \
7476 -serial file:" ${CONSOLE_LOG} " \
7577 -name buildernet-playground \
@@ -86,3 +88,33 @@ exec qemu-system-x86_64 \
8688 -chardev socket,id=virtcon,path=" ${CONSOLE_SOCK} " ,server=on,wait=off \
8789 -device virtio-serial-pci \
8890 -device virtconsole,chardev=virtcon,name=org.qemu.console.0
91+
92+ echo " VM started (PID: $( cat " ${PIDFILE} " ) )"
93+ echo " Waiting for VM to become ready (timeout: ${READYZ_TIMEOUT} s)..."
94+ echo " Console: tail -f ${CONSOLE_LOG} "
95+ echo " Socket: socat -,rawer UNIX-CONNECT:${CONSOLE_SOCK} "
96+
97+ READYZ_URL=" https://localhost:${HAPROXY_HTTPS_PORT} /readyz"
98+ DEADLINE=$(( SECONDS + READYZ_TIMEOUT ))
99+
100+ while (( SECONDS < DEADLINE )) ; do
101+ sleep 5
102+
103+ # Fail fast if QEMU died (bad image, kernel panic, etc.)
104+ if ! kill -0 " $( cat " ${PIDFILE} " ) " 2> /dev/null; then
105+ echo " Error: QEMU process died during boot"
106+ echo " Check console log: tail -f ${CONSOLE_LOG} "
107+ exit 1
108+ fi
109+
110+ HTTP_CODE=$( curl -s -k -o /dev/null -w " %{http_code}" " ${READYZ_URL} " 2> /dev/null || echo " 000" )
111+ if [[ " ${HTTP_CODE} " == " 200" ]]; then
112+ echo " VM ready after $(( READYZ_TIMEOUT - (DEADLINE - SECONDS) )) s (PID: $( cat " ${PIDFILE} " ) )"
113+ exit 0
114+ fi
115+ echo " waiting... $(( READYZ_TIMEOUT - (DEADLINE - SECONDS) )) s (HTTP ${HTTP_CODE} )"
116+ done
117+
118+ echo " Error: VM did not become ready within ${READYZ_TIMEOUT} s"
119+ echo " Check console log: tail -f ${CONSOLE_LOG} "
120+ exit 1
0 commit comments