From f5d0c16f85070861ac21f2bd4507f3a20fd9af4b Mon Sep 17 00:00:00 2001 From: 3x3cut0r Date: Thu, 23 Oct 2025 22:50:10 +0200 Subject: [PATCH 1/3] Improve RDP readiness check before launching VM --- bin/omarchy-windows-vm | 83 ++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/bin/omarchy-windows-vm b/bin/omarchy-windows-vm index eaea4013..2bc18db6 100755 --- a/bin/omarchy-windows-vm +++ b/bin/omarchy-windows-vm @@ -254,6 +254,53 @@ remove_windows() { echo "Windows VM removal completed!" } +wait_for_rdp_ready() { + local WIN_USER="$1" + local WIN_PASS="$2" + + echo "Waiting for Windows VM to be ready..." + + local WAIT_COUNT=0 + while ! nc -z 127.0.0.1 3389 2>/dev/null; do + sleep 2 + WAIT_COUNT=$((WAIT_COUNT + 1)) + if [ $WAIT_COUNT -gt 60 ]; then # 2 minutes timeout for port availability + echo "❌ Timeout waiting for RDP port!" + echo " The VM might still be installing Windows." + echo " Check progress at: http://127.0.0.1:8006" + return 1 + fi + done + + echo "RDP port detected. Verifying login availability..." + + local VERIFY_START=$(date +%s) + local VERIFY_LOG + if ! VERIFY_LOG=$(mktemp); then + echo "❌ Failed to create temporary file for RDP verification." + return 1 + fi + + while true; do + if timeout 5s xfreerdp3 /auth-only /cert:ignore /u:"$WIN_USER" /p:"$WIN_PASS" /v:127.0.0.1:3389 >"$VERIFY_LOG" 2>&1; then + rm -f "$VERIFY_LOG" + return 0 + fi + + if [ $(( $(date +%s) - VERIFY_START )) -ge 25 ]; then + echo "❌ Timeout verifying RDP login readiness!" + if [ -s "$VERIFY_LOG" ]; then + echo " Last attempt output:" + tail -n 10 "$VERIFY_LOG" + fi + rm -f "$VERIFY_LOG" + return 1 + fi + + sleep 1 + done +} + launch_windows() { KEEP_ALIVE=false if [ "$1" = "--keep-alive" ] || [ "$1" = "-k" ]; then @@ -266,6 +313,14 @@ launch_windows() { exit 1 fi + # Extract credentials from compose file + WIN_USER=$(grep "USERNAME:" "$COMPOSE_FILE" | sed 's/.*USERNAME: "\(.*\)"/\1/') + WIN_PASS=$(grep "PASSWORD:" "$COMPOSE_FILE" | sed 's/.*PASSWORD: "\(.*\)"/\1/') + + # Use defaults if not found + [ -z "$WIN_USER" ] && WIN_USER="docker" + [ -z "$WIN_PASS" ] && WIN_PASS="admin" + # Check if container is already running CONTAINER_STATUS=$(docker inspect --format='{{.State.Status}}' omarchy-windows 2>/dev/null) @@ -282,32 +337,12 @@ launch_windows() { notify-send -u critical "Windows VM" "Failed to start Windows VM" exit 1 fi - - # Wait for RDP to be ready - echo "Waiting for Windows VM to be ready..." - WAIT_COUNT=0 - while ! nc -z 127.0.0.1 3389 2>/dev/null; do - sleep 2 - WAIT_COUNT=$((WAIT_COUNT + 1)) - if [ $WAIT_COUNT -gt 60 ]; then # 2 minutes timeout - echo "❌ Timeout waiting for RDP!" - echo " The VM might still be installing Windows." - echo " Check progress at: http://127.0.0.1:8006" - exit 1 - fi - done - - # Give it a moment more to fully initialize - sleep 3 fi - # Extract credentials from compose file - WIN_USER=$(grep "USERNAME:" "$COMPOSE_FILE" | sed 's/.*USERNAME: "\(.*\)"/\1/') - WIN_PASS=$(grep "PASSWORD:" "$COMPOSE_FILE" | sed 's/.*PASSWORD: "\(.*\)"/\1/') - - # Use defaults if not found - [ -z "$WIN_USER" ] && WIN_USER="docker" - [ -z "$WIN_PASS" ] && WIN_PASS="admin" + if ! wait_for_rdp_ready "$WIN_USER" "$WIN_PASS"; then + notify-send -u critical "Windows VM" "RDP not ready yet. Please try again shortly." + exit 1 + fi # Build the connection info if [ "$KEEP_ALIVE" = true ]; then From e8880b5154136e95ac495727fbfcfdd57cebbe58 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 5 Jan 2026 15:10:13 -0500 Subject: [PATCH 2/3] Simplify --- bin/omarchy-windows-vm | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/bin/omarchy-windows-vm b/bin/omarchy-windows-vm index 2bc18db6..5ce9b8d8 100755 --- a/bin/omarchy-windows-vm +++ b/bin/omarchy-windows-vm @@ -257,48 +257,20 @@ remove_windows() { wait_for_rdp_ready() { local WIN_USER="$1" local WIN_PASS="$2" + local TIMEOUT=240 + local SECONDS=0 echo "Waiting for Windows VM to be ready..." - local WAIT_COUNT=0 - while ! nc -z 127.0.0.1 3389 2>/dev/null; do + while ! timeout 5s xfreerdp3 /auth-only /cert:ignore /u:"$WIN_USER" /p:"$WIN_PASS" /v:127.0.0.1:3389 &>/dev/null; do sleep 2 - WAIT_COUNT=$((WAIT_COUNT + 1)) - if [ $WAIT_COUNT -gt 60 ]; then # 2 minutes timeout for port availability - echo "❌ Timeout waiting for RDP port!" + if [ $SECONDS -gt $TIMEOUT ]; then + echo "❌ Timeout waiting for RDP!" echo " The VM might still be installing Windows." echo " Check progress at: http://127.0.0.1:8006" return 1 fi done - - echo "RDP port detected. Verifying login availability..." - - local VERIFY_START=$(date +%s) - local VERIFY_LOG - if ! VERIFY_LOG=$(mktemp); then - echo "❌ Failed to create temporary file for RDP verification." - return 1 - fi - - while true; do - if timeout 5s xfreerdp3 /auth-only /cert:ignore /u:"$WIN_USER" /p:"$WIN_PASS" /v:127.0.0.1:3389 >"$VERIFY_LOG" 2>&1; then - rm -f "$VERIFY_LOG" - return 0 - fi - - if [ $(( $(date +%s) - VERIFY_START )) -ge 25 ]; then - echo "❌ Timeout verifying RDP login readiness!" - if [ -s "$VERIFY_LOG" ]; then - echo " Last attempt output:" - tail -n 10 "$VERIFY_LOG" - fi - rm -f "$VERIFY_LOG" - return 1 - fi - - sleep 1 - done } launch_windows() { From 7118ef6b199d231390bac43899d7d0d988c803c0 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 5 Jan 2026 15:15:56 -0500 Subject: [PATCH 3/3] Correct message --- bin/omarchy-windows-vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/omarchy-windows-vm b/bin/omarchy-windows-vm index 5ce9b8d8..129838f8 100755 --- a/bin/omarchy-windows-vm +++ b/bin/omarchy-windows-vm @@ -312,7 +312,7 @@ launch_windows() { fi if ! wait_for_rdp_ready "$WIN_USER" "$WIN_PASS"; then - notify-send -u critical "Windows VM" "RDP not ready yet. Please try again shortly." + notify-send -u critical "Windows VM" "Did not come alive in time." exit 1 fi