2016-04-15 16:45:21 +08:00
|
|
|
#!/bin/bash
|
|
|
|
echo "Waiting for startup.."
|
2018-03-27 09:26:21 +08:00
|
|
|
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
|
|
|
|
|
2018-03-27 09:26:21 +08:00
|
|
|
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" `
|
2018-03-27 09:26:21 +08:00
|
|
|
mongo --host mongo1:27017 <<EOF
|
2016-04-15 16:45:21 +08:00
|
|
|
var cfg = {
|
|
|
|
"_id": "rs",
|
|
|
|
"version": 1,
|
|
|
|
"members": [
|
|
|
|
{
|
|
|
|
"_id": 0,
|
2018-03-27 09:26:21 +08:00
|
|
|
"host": "mongo1:27017",
|
2016-04-15 16:45:21 +08:00
|
|
|
"priority": 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"_id": 1,
|
2018-03-27 09:26:21 +08:00
|
|
|
"host": "mongo2:27017",
|
2016-04-15 16:45:21 +08:00
|
|
|
"priority": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"_id": 2,
|
2018-03-27 09:26:21 +08:00
|
|
|
"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
|
|
|
|
|
2018-03-27 09:26:21 +08:00
|
|
|
tail -f /dev/null
|