Explorar el Código

Patch to handle zero time in case of absence of PRIMARY

Vadim Surkov hace 6 años
padre
commit
723687f06e
Se han modificado 1 ficheros con 4 adiciones y 0 borrados
  1. 4 0
      mongo-healthcheck.sh

+ 4 - 0
mongo-healthcheck.sh

@@ -26,6 +26,10 @@ if [[ $state == "SECONDARY" ]];then
     date=`mongo --host $myhost --eval 'rs.status().date;' |tail -1`
     dates=`date -d "$date" "+%s"`
     lastHeartbeat=`mongo --host $myhost --quiet --eval 'var i=0; rs.status().members.forEach( function(myDoc) { if (myDoc.stateStr=="PRIMARY") { print(myDoc.lastHeartbeat); i++;} })' |tail -1`
+    if [[ -z "${lastHeartbeat}" ]]; then
+       echo "Zero HartBeat - no PRIMARY !!!"
+       exit 1
+    fi
     datelh=`date -d "$lastHeartbeat" "+%s"`
     if [[ $(($dates-$datelh)) -le "60" ]]; then
         echo "0"