Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 17, 2020 05:18
Show Gist options
  • Save velotiotech/8b4e484f02d786c051ed014a81d12599 to your computer and use it in GitHub Desktop.
Save velotiotech/8b4e484f02d786c051ed014a81d12599 to your computer and use it in GitHub Desktop.
Velotio - HashiCorp Consul Part 2 - MongoDB Replica Set - Check Primary instance using shell script
#!/bin/bash
mongo_primary=$(mongo --quiet --eval 'JSON.stringify(db.isMaster())' | jq -r .ismaster 2> /dev/null)
if [[ $mongo_primary == false ]]; then
exit 1
fi
echo "Mongo primary healthy and reachable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment