From 50298c613d5719702cef880ad7922fcd4fc08465 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Tue, 16 Dec 2025 05:55:54 +0800 Subject: [PATCH 01/16] should override PORT --- registry/coder/modules/kasmvnc/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 6238bdb60..57b970b13 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -292,7 +292,7 @@ VNC_LOG="/tmp/kasmvncserver.log" printf "🚀 Starting KasmVNC server...\n" set +e -kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -disableBasicAuth > "$VNC_LOG" 2>&1 +kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disableBasicAuth > "$VNC_LOG" 2>&1 RETVAL=$? set -e From ed54aa97855c884ba29e8a4c66972f3eee9e7798 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Tue, 16 Dec 2025 06:14:06 +0800 Subject: [PATCH 02/16] add -autokill --- registry/coder/modules/kasmvnc/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 57b970b13..d9a230f59 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -292,7 +292,7 @@ VNC_LOG="/tmp/kasmvncserver.log" printf "🚀 Starting KasmVNC server...\n" set +e -kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disableBasicAuth > "$VNC_LOG" 2>&1 +kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disableBasicAuth -autokill > "$VNC_LOG" 2>&1 RETVAL=$? set -e From d9807e094e20fb820555813ede9f2323feaa3656 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Tue, 16 Dec 2025 06:27:59 +0800 Subject: [PATCH 03/16] rm autokill --- registry/coder/modules/kasmvnc/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index d9a230f59..57b970b13 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -292,7 +292,7 @@ VNC_LOG="/tmp/kasmvncserver.log" printf "🚀 Starting KasmVNC server...\n" set +e -kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disableBasicAuth -autokill > "$VNC_LOG" 2>&1 +kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disableBasicAuth > "$VNC_LOG" 2>&1 RETVAL=$? set -e From 1e78f976b736edf90b915634caad5a77a3235d43 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Tue, 16 Dec 2025 06:37:18 +0800 Subject: [PATCH 04/16] use curl check again --- registry/coder/modules/kasmvnc/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 57b970b13..a18578a42 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -296,7 +296,7 @@ kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disa RETVAL=$? set -e -if [[ $RETVAL -ne 0 ]]; then +if [[ $RETVAL -ne 0 ]] && ! curl -s http://127.0.0.1:"${PORT}"/app; then echo "ERROR: Failed to start KasmVNC server. Return code: $RETVAL" if [[ -f "$VNC_LOG" ]]; then echo "Full logs:" From cf3fbed4b993384181e3f641195adb48d91b5914 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 18:34:05 +0800 Subject: [PATCH 05/16] add health_check_with_retries and check_port_owned_by_user --- registry/coder/modules/kasmvnc/run.sh | 78 ++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index a18578a42..659fac25f 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -282,6 +282,66 @@ patch_kasm_http_files() { fix_server_index_file "$homedir" } +health_check_with_retries() { + local max_attempts=10 + local attempt=1 + local supports_http_code=false + + if command -v curl &> /dev/null; then + check_tool="curl -s -o /dev/null -w '%{http_code}'" + supports_http_code=true + elif command -v wget &> /dev/null; then + check_tool="wget -q -O- --server-response" + elif command -v busybox &> /dev/null; then + check_tool="busybox wget -O-" + else + echo "ERROR: No download tool available (curl, wget, or busybox required)" + exit 1 + fi + + while (( attempt <= max_attempts )); do + status=$($check_tool "http://127.0.0.1:${PORT}/app" 2>/dev/null) + + if $supports_http_code; then + if [[ "$status" == "200" ]]; then + return 0 + fi + else + if [[ -n "$status" ]]; then + return 0 + fi + fi + + echo "Attempt $attempt: service not ready yet" + sleep 1 + ((attempt++)) + done + return 1 +} + +check_port_owned_by_user() { + local port=$1 + local user + user=$(whoami) + if command -v ss &> /dev/null; then + if ss -tlnp 2>/dev/null | awk -v port="$port" -v user="$user" '$4 ~ ":"port && $7 ~ user {exit 0} END {exit 1}'; then + return 0 + fi + fi + if command -v netstat &> /dev/null; then + if netstat -tlnp 2>/dev/null | awk -v port="$port" -v user="$user" '$4 ~ ":"port && $7 ~ user {exit 0} END {exit 1}'; then + return 0 + fi + fi + if command -v lsof &> /dev/null; then + if lsof -iTCP:"$port" -sTCP:LISTEN -n -P 2>/dev/null | awk -v user="$user" '$3 == user {exit 0} END {exit 1}'; then + return 0 + fi + fi + return 1 +} + + if [[ "${SUBDOMAIN}" == "false" ]]; then echo "🩹 Patching up webserver files to support path-sharing..." patch_kasm_http_files @@ -296,15 +356,19 @@ kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disa RETVAL=$? set -e -if [[ $RETVAL -ne 0 ]] && ! curl -s http://127.0.0.1:"${PORT}"/app; then - echo "ERROR: Failed to start KasmVNC server. Return code: $RETVAL" - if [[ -f "$VNC_LOG" ]]; then - echo "Full logs:" - cat "$VNC_LOG" +if [[ $RETVAL -ne 0 ]]; then + if check_port_owned_by_user "$PORT"; then + echo "Port $PORT is already owned by $(whoami), running health check..." + if ! health_check_with_retries; then + echo "ERROR: KasmVNC server on port $PORT failed health check" + [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" + exit 1 + fi else - echo "ERROR: Log file not found: $VNC_LOG" + echo "ERROR: Failed to start KasmVNC server. Return code: $RETVAL" + [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" + exit 1 fi - exit 1 fi printf "🚀 KasmVNC server started successfully!\n" From 582adaa3518276b26c28ae6f83c725365a6bd415 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 18:42:31 +0800 Subject: [PATCH 06/16] fix %{http_code} --- registry/coder/modules/kasmvnc/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 659fac25f..00637a866 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -283,12 +283,12 @@ patch_kasm_http_files() { } health_check_with_retries() { - local max_attempts=10 + local max_attempts=3 local attempt=1 local supports_http_code=false if command -v curl &> /dev/null; then - check_tool="curl -s -o /dev/null -w '%{http_code}'" + check_tool="curl -s -o /dev/null -w '%%{http_code}'" supports_http_code=true elif command -v wget &> /dev/null; then check_tool="wget -q -O- --server-response" From 469f1cd6ee5be995c922bdf2c0af06a2dae9d1cd Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 18:44:08 +0800 Subject: [PATCH 07/16] fix $PORT --- registry/coder/modules/kasmvnc/run.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 00637a866..fc50a22c7 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -357,10 +357,10 @@ RETVAL=$? set -e if [[ $RETVAL -ne 0 ]]; then - if check_port_owned_by_user "$PORT"; then - echo "Port $PORT is already owned by $(whoami), running health check..." + if check_port_owned_by_user "${PORT}"; then + echo "Port ${PORT} is already owned by $(whoami), running health check..." if ! health_check_with_retries; then - echo "ERROR: KasmVNC server on port $PORT failed health check" + echo "ERROR: KasmVNC server on port ${PORT} failed health check" [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" exit 1 fi From 6bc45585605ff1ff5103651c9c34313e2fb07126 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 18:50:11 +0800 Subject: [PATCH 08/16] fix check_port_owned_by_user --- registry/coder/modules/kasmvnc/run.sh | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index fc50a22c7..a0f303dcc 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -320,23 +320,23 @@ health_check_with_retries() { } check_port_owned_by_user() { - local port=$1 + local port="$1" local user - user=$(whoami) - if command -v ss &> /dev/null; then - if ss -tlnp 2>/dev/null | awk -v port="$port" -v user="$user" '$4 ~ ":"port && $7 ~ user {exit 0} END {exit 1}'; then - return 0 - fi + user="$(whoami)" + if command -v ss >/dev/null 2>&1; then + ss -H -tlnp 2>/dev/null | + awk -v p=":$port" -v u="$user" '$4 ~ p && $7 ~ u {found=1} END {exit !found}' + return $? fi - if command -v netstat &> /dev/null; then - if netstat -tlnp 2>/dev/null | awk -v port="$port" -v user="$user" '$4 ~ ":"port && $7 ~ user {exit 0} END {exit 1}'; then - return 0 - fi + if command -v netstat >/dev/null 2>&1; then + netstat -tlnp 2>/dev/null | + awk -v p=":$port" -v u="$user" '$4 ~ p && $7 ~ u {found=1} END {exit !found}' + return $? fi - if command -v lsof &> /dev/null; then - if lsof -iTCP:"$port" -sTCP:LISTEN -n -P 2>/dev/null | awk -v user="$user" '$3 == user {exit 0} END {exit 1}'; then - return 0 - fi + if command -v lsof >/dev/null 2>&1; then + lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null | + awk -v u="$user" '$3 == u {found=1} END {exit !found}' + return $? fi return 1 } From e39a0128d9a6f1048057b0583a74189453fae361 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 18:53:36 +0800 Subject: [PATCH 09/16] debug --- registry/coder/modules/kasmvnc/run.sh | 62 +++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index a0f303dcc..93534db57 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -319,25 +319,67 @@ health_check_with_retries() { return 1 } +debug() { + [[ "${DEBUG:-0}" == "1" ]] && echo "[DEBUG] $*" >&2 +} + check_port_owned_by_user() { local port="$1" local user user="$(whoami)" + + debug "Checking port: $port" + debug "Current user: $user" + if command -v ss >/dev/null 2>&1; then - ss -H -tlnp 2>/dev/null | - awk -v p=":$port" -v u="$user" '$4 ~ p && $7 ~ u {found=1} END {exit !found}' - return $? + debug "Using ss" + + local out + out="$(ss -H -tlnp 2>&1)" + debug "ss output:" + debug "$out" + + echo "$out" | awk -v p=":$port" -v u="$user" ' + $4 ~ p && $7 ~ u { found=1 } + END { exit !found } + ' && return 0 + + return 1 fi + if command -v netstat >/dev/null 2>&1; then - netstat -tlnp 2>/dev/null | - awk -v p=":$port" -v u="$user" '$4 ~ p && $7 ~ u {found=1} END {exit !found}' - return $? + debug "Using netstat" + + local out + out="$(netstat -tlnp 2>&1)" + debug "netstat output:" + debug "$out" + + echo "$out" | awk -v p=":$port" -v u="$user" ' + $4 ~ p && $7 ~ u { found=1 } + END { exit !found } + ' && return 0 + + return 1 fi + if command -v lsof >/dev/null 2>&1; then - lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null | - awk -v u="$user" '$3 == u {found=1} END {exit !found}' - return $? + debug "Using lsof" + + local out + out="$(lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>&1)" + debug "lsof output:" + debug "$out" + + echo "$out" | awk -v u="$user" ' + $3 == u { found=1 } + END { exit !found } + ' && return 0 + + return 1 fi + + debug "No ss / netstat / lsof available" return 1 } @@ -357,6 +399,8 @@ RETVAL=$? set -e if [[ $RETVAL -ne 0 ]]; then + export DEBUG=1 + debug "KasmVNC error code: $RETVAL" if check_port_owned_by_user "${PORT}"; then echo "Port ${PORT} is already owned by $(whoami), running health check..." if ! health_check_with_retries; then From 484936a9d6f91403176be39d75332412ebf4c341 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 18:55:16 +0800 Subject: [PATCH 10/16] test --- registry/coder/modules/kasmvnc/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 93534db57..41ade3f2d 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -320,7 +320,7 @@ health_check_with_retries() { } debug() { - [[ "${DEBUG:-0}" == "1" ]] && echo "[DEBUG] $*" >&2 + [[ "$${DEBUG:-0}" == "1" ]] && echo "[DEBUG] $*" >&2 } check_port_owned_by_user() { From b88d30abdb623dfcce0777b01f602473744a80e8 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 19:04:56 +0800 Subject: [PATCH 11/16] test --- registry/coder/modules/kasmvnc/run.sh | 79 +++++++++------------------ 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 41ade3f2d..23b60f825 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -323,64 +323,39 @@ debug() { [[ "$${DEBUG:-0}" == "1" ]] && echo "[DEBUG] $*" >&2 } +warn() { + echo "[WARN] $*" >&2 +} + check_port_owned_by_user() { local port="$1" local user user="$(whoami)" - debug "Checking port: $port" - debug "Current user: $user" - - if command -v ss >/dev/null 2>&1; then - debug "Using ss" - - local out - out="$(ss -H -tlnp 2>&1)" - debug "ss output:" - debug "$out" - - echo "$out" | awk -v p=":$port" -v u="$user" ' - $4 ~ p && $7 ~ u { found=1 } - END { exit !found } - ' && return 0 - + if ! command -v lsof >/dev/null 2>&1; then + warn "lsof not found, skip port ownership check" return 1 fi - if command -v netstat >/dev/null 2>&1; then - debug "Using netstat" + debug "Checking port $port with lsof (user=$user)" - local out - out="$(netstat -tlnp 2>&1)" - debug "netstat output:" - debug "$out" + local out + out="$(lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null)" - echo "$out" | awk -v p=":$port" -v u="$user" ' - $4 ~ p && $7 ~ u { found=1 } - END { exit !found } - ' && return 0 + debug "lsof output:" + debug "$out" + if [[ -z "$out" ]]; then + debug "No process is listening on port $port" return 1 fi - if command -v lsof >/dev/null 2>&1; then - debug "Using lsof" - - local out - out="$(lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>&1)" - debug "lsof output:" - debug "$out" - - echo "$out" | awk -v u="$user" ' - $3 == u { found=1 } - END { exit !found } - ' && return 0 - + if ! echo "$out" | awk -v u="$user" '$3 == u {found=1} END {exit !found}'; then + debug "Port $port is not owned by user $user" return 1 fi - debug "No ss / netstat / lsof available" - return 1 + return 0 } @@ -401,18 +376,18 @@ set -e if [[ $RETVAL -ne 0 ]]; then export DEBUG=1 debug "KasmVNC error code: $RETVAL" - if check_port_owned_by_user "${PORT}"; then - echo "Port ${PORT} is already owned by $(whoami), running health check..." - if ! health_check_with_retries; then - echo "ERROR: KasmVNC server on port ${PORT} failed health check" - [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" - exit 1 - fi - else - echo "ERROR: Failed to start KasmVNC server. Return code: $RETVAL" - [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" - exit 1 + if [[ $RETVAL -eq 255 ]]; then + if check_port_owned_by_user "${PORT}"; then + echo "Port ${PORT} is already owned by $(whoami), running health check..." + if ! health_check_with_retries; then + echo "ERROR: KasmVNC server on port ${PORT} failed health check" + [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" + exit 1 + fi fi + echo "ERROR: Failed to start KasmVNC server. Return code: $RETVAL" + [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" + exit 1 fi printf "🚀 KasmVNC server started successfully!\n" From 9561764937592452329d2f2404d23f11f0e325b9 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 19:07:32 +0800 Subject: [PATCH 12/16] fix --- registry/coder/modules/kasmvnc/run.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 23b60f825..599015598 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -376,15 +376,22 @@ set -e if [[ $RETVAL -ne 0 ]]; then export DEBUG=1 debug "KasmVNC error code: $RETVAL" + if [[ $RETVAL -eq 255 ]]; then if check_port_owned_by_user "${PORT}"; then echo "Port ${PORT} is already owned by $(whoami), running health check..." - if ! health_check_with_retries; then + + if health_check_with_retries; then + debug "Health check succeeded, treating as success" + exit 0 + else echo "ERROR: KasmVNC server on port ${PORT} failed health check" [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" exit 1 fi + fi fi + echo "ERROR: Failed to start KasmVNC server. Return code: $RETVAL" [[ -f "$VNC_LOG" ]] && cat "$VNC_LOG" exit 1 From 97d3340058f69f0c229f2e6f71cc0a21d88467cc Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 19:13:49 +0800 Subject: [PATCH 13/16] format warn and debug --- registry/coder/modules/kasmvnc/run.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 599015598..1b03deeb7 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -3,10 +3,19 @@ set -eo pipefail error() { - printf "💀 ERROR: %s\n" "$@" + printf "💀 ERROR: %s\n" "$*" >&2 exit 1 } +warn() { + printf "⚠️ WARN: %s\n" "$*" >&2 +} + +debug() { + [[ "$${DEBUG:-0}" == "1" ]] || return 0 + printf "🐛 DEBUG: %s\n" "$*" >&2 +} + # Function to check if KasmVNC is already installed check_installed() { if command -v kasmvncserver &> /dev/null; then @@ -319,13 +328,6 @@ health_check_with_retries() { return 1 } -debug() { - [[ "$${DEBUG:-0}" == "1" ]] && echo "[DEBUG] $*" >&2 -} - -warn() { - echo "[WARN] $*" >&2 -} check_port_owned_by_user() { local port="$1" From d59ed929b0eba6a094002e985cf30a1eb89bb52f Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 19:17:55 +0800 Subject: [PATCH 14/16] rewrite health_check_with_retries --- registry/coder/modules/kasmvnc/run.sh | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 1b03deeb7..8a5212396 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -294,37 +294,29 @@ patch_kasm_http_files() { health_check_with_retries() { local max_attempts=3 local attempt=1 - local supports_http_code=false + local check_tool if command -v curl &> /dev/null; then - check_tool="curl -s -o /dev/null -w '%%{http_code}'" - supports_http_code=true + check_tool=(curl -s -f -o /dev/null) elif command -v wget &> /dev/null; then - check_tool="wget -q -O- --server-response" + check_tool=(wget -q -O-) elif command -v busybox &> /dev/null; then - check_tool="busybox wget -O-" + check_tool=(busybox wget -O-) else - echo "ERROR: No download tool available (curl, wget, or busybox required)" - exit 1 + error "No download tool available (curl, wget, or busybox required)" fi while (( attempt <= max_attempts )); do - status=$($check_tool "http://127.0.0.1:${PORT}/app" 2>/dev/null) - - if $supports_http_code; then - if [[ "$status" == "200" ]]; then - return 0 - fi - else - if [[ -n "$status" ]]; then - return 0 - fi + if "${check_tool[@]}" "http://127.0.0.1:${PORT}/app" >/dev/null 2>&1; then + debug "Attempt $attempt: service is ready" + return 0 fi echo "Attempt $attempt: service not ready yet" sleep 1 ((attempt++)) done + return 1 } From ec95aae6c97a1b9325770485d6c47f609ba3a896 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 19:19:38 +0800 Subject: [PATCH 15/16] fix --- registry/coder/modules/kasmvnc/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 8a5212396..9d7a69b75 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -307,7 +307,7 @@ health_check_with_retries() { fi while (( attempt <= max_attempts )); do - if "${check_tool[@]}" "http://127.0.0.1:${PORT}/app" >/dev/null 2>&1; then + if "$${check_tool[@]}" "http://127.0.0.1:${PORT}/app" >/dev/null 2>&1; then debug "Attempt $attempt: service is ready" return 0 fi From 24919cf2036e9f55149da468972a3addfec17556 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 17 Dec 2025 19:21:31 +0800 Subject: [PATCH 16/16] cleanup --- registry/coder/modules/kasmvnc/run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/registry/coder/modules/kasmvnc/run.sh b/registry/coder/modules/kasmvnc/run.sh index 9d7a69b75..2ec5a5879 100644 --- a/registry/coder/modules/kasmvnc/run.sh +++ b/registry/coder/modules/kasmvnc/run.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +# DEBUG=1 set -eo pipefail error() { @@ -368,7 +369,7 @@ RETVAL=$? set -e if [[ $RETVAL -ne 0 ]]; then - export DEBUG=1 + debug "KasmVNC error code: $RETVAL" if [[ $RETVAL -eq 255 ]]; then