docker-compose-files/mongo_cluster/scripts/mongosetup.sh

42 lines
948 B
Bash
Raw Normal View History

2016-04-15 16:45:21 +08:00
#!/bin/bash
echo "Waiting for startup.."
until curl http://mongo1:28017/serverStatus\?text\=1 2>&1 | grep uptime | head -1; do
2016-04-15 16:45:21 +08:00
printf '.'
sleep 1
done
echo curl http://mongo1:28017/serverStatus\?text\=1 2>&1 | grep uptime | head -1
2016-04-15 16:45:21 +08:00
echo "Started.."
sleep 10
echo SETUP.sh time now: `date +"%T" `
mongo --host mongo1:27017 <<EOF
2016-04-15 16:45:21 +08:00
var cfg = {
"_id": "rs",
"version": 1,
"members": [
{
"_id": 0,
"host": "mongo1:27017",
2016-04-15 16:45:21 +08:00
"priority": 2
},
{
"_id": 1,
"host": "mongo2:27017",
2016-04-15 16:45:21 +08:00
"priority": 0
},
{
"_id": 2,
"host": "mongo3:27017",
2016-04-15 16:45:21 +08:00
"priority": 0
}
]
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
db.getMongo().setReadPref('nearest');
EOF
tail -f /dev/null