From f308484f4d3938acf88aeed92fbd58c2906e3d07 Mon Sep 17 00:00:00 2001 From: Eddy de Vink Date: Mon, 19 Oct 2026 10:48:12 +0200 Subject: [PATCH] fix: guard grep -c || echo 0 gaf 0\n0 bij nul matches -> integer-fout; vervangen door grep -q + ssh-exitcode-logica --- deploy/netcup-standby-guard.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/deploy/netcup-standby-guard.sh b/deploy/netcup-standby-guard.sh index ac9fe84..af18e69 100755 --- a/deploy/netcup-standby-guard.sh +++ b/deploy/netcup-standby-guard.sh @@ -64,23 +64,27 @@ if ! ssh_nc 'true' >/dev/null 2>&1; then fi # 2) netcup-multiplexer al op STANDBY? -nc_st=$(ssh_nc "grep -c '^Environment=STANDBY=1' $UNIT 2>/dev/null || echo 0") || exit 0 -if [ "${nc_st:-0}" -ge 1 ]; then +if ssh_nc "grep -q '^Environment=STANDBY=1' $UNIT 2>/dev/null"; then [ "$(state)" = "flipped" ] || log "netcup-multiplexer staat al op STANDBY — niets te doen" echo flipped >"$STATEFILE" exit 0 fi -# 3) nextcloud moet actief zijn; anders is netcup-actief een bewuste failover -nccl_st=$(ssh_nccl "grep -c '^Environment=STANDBY=1' $UNIT 2>/dev/null || echo 0") -case "${nccl_st:-}" in - ''|*[!0-9]*) log "nextcloud-unit onleesbaar — netcup niet aanraken (kan bewuste failover zijn)"; echo unknown >"$STATEFILE"; exit 0;; -esac -if [ "$nccl_st" -ge 1 ]; then +# 3) nextcloud moet actief zijn; anders is netcup-actief een bewuste failover. +# rc: 0=STANDBY aanwezig, 1=bereikbaar+zonder STANDBY (actief), 255=onbereikbaar, 2=unit onleesbaar +ssh_nccl "grep -q '^Environment=STANDBY=1' $UNIT 2>/dev/null" +nccl_rc=$? +if [ "$nccl_rc" -eq 0 ]; then [ "$(state)" = "deliberate" ] || log "nextcloud staat op STANDBY -> netcup actief is de bewuste richting; geen flip" echo deliberate >"$STATEFILE" exit 0 fi +if [ "$nccl_rc" -ne 1 ]; then + [ "$(state)" = "unknown" ] || log "nextcloud niet bevestigd actief (ssh rc=$nccl_rc) — netcup niet aanraken (kan bewuste failover zijn)" + echo unknown >"$STATEFILE" + exit 0 +fi +# rc==1: nextcloud bereikbaar + géén STANDBY = actief # 4) FLIP: netcup zonder STANDBY terwijl nextcloud actief is log "FLIP: netcup terug + nextcloud actief -> netcup-multiplexer op STANDBY zetten"