Created
November 13, 2024 18:09
-
-
Save sibelius/a9a2dfd32c72955ea61fb0a4779e4b10 to your computer and use it in GitHub Desktop.
mongodb-rs.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
args="$@" | |
docker-compose up -d $args | |
sleep 5 | |
updateEtcHost() { | |
local content=$1 | |
if grep -q "$content" /etc/hosts; then | |
echo "Line already exists in /etc/hosts. No changes made." | |
else | |
# Append the line to /etc/hosts | |
echo "$content" | sudo tee -a /etc/hosts | |
echo "Line added to /etc/hosts." | |
fi | |
} | |
updateEtcHost '172.20.0.2 mongo1' | |
updateEtcHost '172.20.0.3 mongo2' | |
updateEtcHost '172.20.0.4 mongo-hidden' | |
if [[ -z $args || $args != *"mongo-hidden"* ]]; then | |
docker exec mongo1 ./scripts/rs-init.sh | |
sleep 5 | |
source scripts/mongodb/mongo-reconfigure.sh | |
else | |
docker exec mongo1 ./scripts/rs-init-hidden.sh | |
sleep 5 | |
source scripts/mongodb/mongo-reconfigure-hidden.sh | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mongosh <<EOF | |
const config = { | |
"_id": "rs0", | |
"version": 1, | |
"members": [ | |
{ | |
"_id": 1, | |
"host": "mongo1:27017", | |
"priority": 2 | |
}, | |
{ | |
"_id": 2, | |
"host": "mongo2:27017", | |
"priority": 1 | |
}, | |
] | |
}; | |
rs.initiate(config, { force: true }); | |
rs.status(); | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment