From c7268ade8ec985a078c57582a34e82ad7d8b8524 Mon Sep 17 00:00:00 2001 From: beatzaplenty Date: Wed, 29 Jul 2026 01:29:04 +1000 Subject: [PATCH] fix(ha/cluster-init): detect StandAlone DRBD state in sync wait loop If the DRBD peer connection drops during the initial sync wait (cs:StandAlone), the loop would spin forever printing "waiting for sync progress" with no indication of what's wrong. Now parses cs: from /proc/drbd each tick and dies with a clear error if StandAlone is detected. Also shows the cs: field in the non-syncing message so the actual connection state is always visible. Co-Authored-By: Claude Sonnet 4.6 --- scripts/ha/cluster-init.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/ha/cluster-init.sh b/scripts/ha/cluster-init.sh index 5fe89a7..b226f7b 100755 --- a/scripts/ha/cluster-init.sh +++ b/scripts/ha/cluster-init.sh @@ -250,17 +250,23 @@ while true; do log "DRBD initial sync complete (dstate: $_dstate)" break fi + # Parse connection state from /proc/drbd (cs:SyncSource, cs:Connected, cs:StandAlone …) + _cs=$(grep -oE 'cs:[A-Za-z]+' /proc/drbd 2>/dev/null | head -1 | sed 's/cs://' || echo "unknown") # /proc/drbd uses variable whitespace: "sync'ed: 5.2%" (two spaces). _pct=$(grep -oE "sync'ed:[[:space:]]+[0-9.]+" /proc/drbd 2>/dev/null | grep -oE "[0-9.]+" | head -1 || echo "") _eta=$(grep -oE "finish:[[:space:]]+[0-9:]+" /proc/drbd 2>/dev/null | grep -oE "[0-9:]+$" | head -1 || echo "") _spd=$(grep -oE "speed:[[:space:]]+[0-9,]+" /proc/drbd 2>/dev/null | grep -oE "[0-9,]+$" | head -1 || echo "") _sync_iter=$(( _sync_iter + 1 )) _sc="${_sync_chars[$_sync_iter % 4]}" - if [[ -n "$_pct" ]]; then + if [[ "$_cs" == "StandAlone" ]]; then + printf "\r%-80s\r" "" + die "DRBD is StandAlone — peer connection lost (dstate: $_dstate). " \ + "Check corosync/network and re-run cluster-init." + elif [[ -n "$_pct" ]]; then printf "\r [%s] syncing: %s%% done — ETA %s @ %s K/s " \ "$_sc" "$_pct" "${_eta:-??:??:??}" "${_spd:-?}" else - printf "\r [%s] dstate: %s — waiting for sync progress " "$_sc" "$_dstate" + printf "\r [%s] cs:%s dstate:%s — waiting for sync to start " "$_sc" "$_cs" "$_dstate" fi sleep 3 done