fix: guard grep -c || echo 0 gaf 0\n0 bij nul matches -> integer-fout; vervangen door grep -q + ssh-exitcode-logica
This commit is contained in:
parent
909c78469b
commit
f308484f4d
1 changed files with 12 additions and 8 deletions
|
|
@ -64,23 +64,27 @@ if ! ssh_nc 'true' >/dev/null 2>&1; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2) netcup-multiplexer al op STANDBY?
|
# 2) netcup-multiplexer al op STANDBY?
|
||||||
nc_st=$(ssh_nc "grep -c '^Environment=STANDBY=1' $UNIT 2>/dev/null || echo 0") || exit 0
|
if ssh_nc "grep -q '^Environment=STANDBY=1' $UNIT 2>/dev/null"; then
|
||||||
if [ "${nc_st:-0}" -ge 1 ]; then
|
|
||||||
[ "$(state)" = "flipped" ] || log "netcup-multiplexer staat al op STANDBY — niets te doen"
|
[ "$(state)" = "flipped" ] || log "netcup-multiplexer staat al op STANDBY — niets te doen"
|
||||||
echo flipped >"$STATEFILE"
|
echo flipped >"$STATEFILE"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3) nextcloud moet actief zijn; anders is netcup-actief een bewuste failover
|
# 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")
|
# rc: 0=STANDBY aanwezig, 1=bereikbaar+zonder STANDBY (actief), 255=onbereikbaar, 2=unit onleesbaar
|
||||||
case "${nccl_st:-}" in
|
ssh_nccl "grep -q '^Environment=STANDBY=1' $UNIT 2>/dev/null"
|
||||||
''|*[!0-9]*) log "nextcloud-unit onleesbaar — netcup niet aanraken (kan bewuste failover zijn)"; echo unknown >"$STATEFILE"; exit 0;;
|
nccl_rc=$?
|
||||||
esac
|
if [ "$nccl_rc" -eq 0 ]; then
|
||||||
if [ "$nccl_st" -ge 1 ]; then
|
|
||||||
[ "$(state)" = "deliberate" ] || log "nextcloud staat op STANDBY -> netcup actief is de bewuste richting; geen flip"
|
[ "$(state)" = "deliberate" ] || log "nextcloud staat op STANDBY -> netcup actief is de bewuste richting; geen flip"
|
||||||
echo deliberate >"$STATEFILE"
|
echo deliberate >"$STATEFILE"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
# 4) FLIP: netcup zonder STANDBY terwijl nextcloud actief is
|
||||||
log "FLIP: netcup terug + nextcloud actief -> netcup-multiplexer op STANDBY zetten"
|
log "FLIP: netcup terug + nextcloud actief -> netcup-multiplexer op STANDBY zetten"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue