fix(ha/cluster-init): drop TTY detection, always use \r for sync progress
Check NixOS configurations / eval-hosts (push) Successful in 10m23s

The TTY check ([[ -t 1 ]]) evaluated false under sudo, causing each update
to print on a new line via log(). Since \r worked correctly in the original
code (user confirmed), drop the branching and always use printf \r.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-29 00:55:31 +10:00
co-authored by Claude Sonnet 4.6
parent 6d16eaff89
commit ceb491b18d
+4 -19
View File
@@ -242,40 +242,25 @@ drbdadm primary ha-data --force
log "Waiting for DRBD initial sync to complete (32 GB may take 1020 min)..."
log " (monitor with: watch -n3 cat /proc/drbd)"
_sync_chars=('|' '/' '-' $'\\')
_sync_last_pct=""
_sync_iter=0
_is_tty=false; [[ -t 1 ]] && _is_tty=true
while true; do
_dstate=$(drbdadm dstate ha-data 2>/dev/null || echo "unknown")
if echo "$_dstate" | grep -q "UpToDate/UpToDate"; then
$_is_tty && printf "\r%-80s\r" ""
printf "\r%-80s\r" ""
log "DRBD initial sync complete (dstate: $_dstate)"
break
fi
# /proc/drbd uses variable whitespace: "sync'ed: 5.2%" (two spaces).
# Use [[:space:]]+ to tolerate any amount of whitespace after the colon.
_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
_msg=" [${_sc}] syncing: ${_pct}% done — ETA ${_eta:-??:??:??} @ ${_spd:-?} K/s"
if $_is_tty; then
printf "\r%-80s" "$_msg"
elif [[ "$_pct" != "$_sync_last_pct" ]]; then
log "$_msg"
_sync_last_pct="$_pct"
fi
printf "\r [%s] syncing: %s%% done — ETA %s @ %s K/s " \
"$_sc" "$_pct" "${_eta:-??:??:??}" "${_spd:-?}"
else
# /proc/drbd shows cs:SyncSource but no percent line yet — or something unexpected.
_msg=" [${_sc}] dstate: ${_dstate} — waiting for sync progress in /proc/drbd"
if $_is_tty; then
printf "\r%-80s" "$_msg"
elif (( _sync_iter % 5 == 1 )); then
log "$_msg"
fi
printf "\r [%s] dstate: %s — waiting for sync progress " "$_sc" "$_dstate"
fi
sleep 3
done