|
@@ -0,0 +1,30 @@
|
|
|
+
|
|
|
+if [[ -n $1 ]]; then
|
|
|
+ myhost=$1
|
|
|
+else
|
|
|
+ myhost=localhost:27017
|
|
|
+fi
|
|
|
+
|
|
|
+EVAL="var i=0; rs.status().members.forEach( function(myDoc) { if (myDoc.name==\"$myhost\") { print(myDoc.stateStr); i++;} })"
|
|
|
+
|
|
|
+state=`echo $EVAL | mongo --host $myhost --quiet |tail -1`
|
|
|
+
|
|
|
+
|
|
|
+if [[ $state == "PRIMARY" ]];then
|
|
|
+ echo "0"
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+
|
|
|
+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`
|
|
|
+ datelh=`date -d "$lastHeartbeat" "+%s"`
|
|
|
+ if [[ $(($dates-$datelh)) -le "60" ]]; then
|
|
|
+ echo "0"
|
|
|
+ exit 0
|
|
|
+ fi
|
|
|
+fi
|
|
|
+
|
|
|
+echo "1"
|
|
|
+exit 1
|