-
Notifications
You must be signed in to change notification settings - Fork 49
feat: re-add daemonize to start.sh and loop waiting for ./readyz #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,14 +62,16 @@ echo " Console socket: ${CONSOLE_SOCK}" | |||||||||||||||
|
|
||||||||||||||||
| source "${SCRIPT_DIR}/ovmf.sh" | ||||||||||||||||
|
|
||||||||||||||||
| READYZ_TIMEOUT="${READYZ_TIMEOUT:-300}" | ||||||||||||||||
|
|
||||||||||||||||
| echo "start.sh: launching qemu-system-x86_64..." | ||||||||||||||||
| echo "start.sh: QEMU_ACCEL_ARGS=${QEMU_ACCEL_ARGS[*]}" | ||||||||||||||||
| echo "start.sh: VM_IMAGE=${VM_IMAGE} ($(du -h "${VM_IMAGE}" | cut -f1))" | ||||||||||||||||
| echo "start.sh: VM_DATA_DISK=${VM_DATA_DISK}" | ||||||||||||||||
|
|
||||||||||||||||
| # exec replaces this shell with QEMU so the playground can track and kill | ||||||||||||||||
| # the process directly. QEMU runs in the foreground (no -daemonize). | ||||||||||||||||
| exec qemu-system-x86_64 \ | ||||||||||||||||
| # QEMU daemonizes (forks into background) | ||||||||||||||||
| qemu-system-x86_64 \ | ||||||||||||||||
| -daemonize \ | ||||||||||||||||
| -pidfile "${PIDFILE}" \ | ||||||||||||||||
| -serial file:"${CONSOLE_LOG}" \ | ||||||||||||||||
| -name buildernet-playground \ | ||||||||||||||||
|
|
@@ -86,3 +88,33 @@ exec qemu-system-x86_64 \ | |||||||||||||||
| -chardev socket,id=virtcon,path="${CONSOLE_SOCK}",server=on,wait=off \ | ||||||||||||||||
| -device virtio-serial-pci \ | ||||||||||||||||
| -device virtconsole,chardev=virtcon,name=org.qemu.console.0 | ||||||||||||||||
|
|
||||||||||||||||
| echo "VM started (PID: $(cat "${PIDFILE}"))" | ||||||||||||||||
| echo "Waiting for VM to become ready (timeout: ${READYZ_TIMEOUT}s)..." | ||||||||||||||||
| echo " Console: tail -f ${CONSOLE_LOG}" | ||||||||||||||||
| echo " Socket: socat -,rawer UNIX-CONNECT:${CONSOLE_SOCK}" | ||||||||||||||||
|
|
||||||||||||||||
| READYZ_URL="https://localhost:${HAPROXY_HTTPS_PORT}/readyz" | ||||||||||||||||
| DEADLINE=$(( SECONDS + READYZ_TIMEOUT )) | ||||||||||||||||
|
|
||||||||||||||||
| while (( SECONDS < DEADLINE )); do | ||||||||||||||||
| sleep 5 | ||||||||||||||||
|
|
||||||||||||||||
| # Fail fast if QEMU died (bad image, kernel panic, etc.) | ||||||||||||||||
| if ! kill -0 "$(cat "${PIDFILE}")" 2>/dev/null; then | ||||||||||||||||
| echo "Error: QEMU process died during boot" | ||||||||||||||||
| echo " Check console log: tail -f ${CONSOLE_LOG}" | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| HTTP_CODE=$(curl -s -k -o /dev/null -w "%{http_code}" "${READYZ_URL}" 2>/dev/null || echo "000") | ||||||||||||||||
| if [[ "${HTTP_CODE}" == "200" ]]; then | ||||||||||||||||
| echo "VM ready after $(( READYZ_TIMEOUT - (DEADLINE - SECONDS) ))s (PID: $(cat "${PIDFILE}"))" | ||||||||||||||||
| exit 0 | ||||||||||||||||
| fi | ||||||||||||||||
| echo " waiting... $(( READYZ_TIMEOUT - (DEADLINE - SECONDS) ))s (HTTP ${HTTP_CODE})" | ||||||||||||||||
| done | ||||||||||||||||
|
|
||||||||||||||||
| echo "Error: VM did not become ready within ${READYZ_TIMEOUT}s" | ||||||||||||||||
| echo " Check console log: tail -f ${CONSOLE_LOG}" | ||||||||||||||||
| exit 1 | ||||||||||||||||
|
Comment on lines
+118
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On timeout, the QEMU VM is still running in the background but the user isn't told. Consider adding a hint to run
Suggested change
|
||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop sleeps 5s before the first health check. If the VM is already ready (or becomes ready quickly), this adds an unnecessary delay. Consider checking first, then sleeping: