diff --git a/failover.ps1 b/failover.ps1 index aa7afe5..bd01752 100644 --- a/failover.ps1 +++ b/failover.ps1 @@ -4,6 +4,12 @@ $nodeList = docker node ls --format '{{json .}}'| ConvertFrom-Json | ForEach-Obj docker node inspect $_.ID | ConvertFrom-Json } $onlineNodeList = $nodeList | Where-Object {$_.Spec.Availability -eq 'active'} +$offlineNodeList = $nodeList | Where-Object {$_.Spec.Availability -ne 'active'} + +if (!$offlineNodeList.Count) { + Write-Output 'all hosts online, nothing to failover' + exit +} $failoverAddressList = (Invoke-RestMethod -Uri 'https://robot-ws.your-server.de/failover' -Authentication Basic -Credential $hetznerCredentials).failover $offlineAddressList = $failoverAddressList | Where-Object active_server_ip -notin $onlineNodeList.Status.Addr