Use mongosetup image

pull/1/head
Baohua Yang 2015-08-21 17:03:19 +08:00
parent da80fd7da4
commit f868847354
2 changed files with 2 additions and 59 deletions

View File

@ -15,18 +15,13 @@ mongo:
- "27017" - "27017"
- "28017" - "28017"
restart: always restart: always
entrypoint: [ "/usr/bin/mongod", "--replSet", "rs", "--smallfiles" ] entrypoint: [ "/usr/bin/mongod", "--replSet", "rs", "--smallfiles", "--httpinterface", "--rest" ]
mongosetup: mongosetup:
image: mongo:3.0 image: yeasy/mongosetup
mem_limit: 1024m mem_limit: 1024m
environment:
- TZ=Asia/Shanghai
links: links:
- mongo:mongo - mongo:mongo
volumes:
- ./scripts:/scripts
entrypoint: [ "bash", "/scripts/mongosetup.sh" ]
elasticsearch: elasticsearch:
image: elasticsearch:1.7 image: elasticsearch:1.7

View File

@ -1,52 +0,0 @@
#!/bin/bash
MONGODB1=`ping -c 1 mongo | head -1 | cut -d "(" -f 2 | cut -d ")" -f 1`
echo "Waiting for startup.."
until curl http://${MONGODB1}:28017/serverStatus\?text\=1 2>&1 | grep uptime | head -1; do
printf '.'
sleep 2
done
echo curl http://${MONGODB1}:28017/serverStatus\?text\=1 2>&1 | grep uptime | head -1
echo "Started.."
sleep 15
echo SETUP time now: `date +"%T" `
mongo --host ${MONGODB1}:27017 <<EOF
var cfg = {
"_id": "rs",
"version": 1,
"members": [
{
"_id": 0,
"host": "${MONGODB1}:27017",
"priority": 1
}
]
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
db.getMongo().setReadPref('nearest');
EOF
echo "rs.isMaster()" > is_master_check
is_master_result=`mongo --host ${MONGODB1} < is_master_check`
expected_result="\"ismaster\" : true"
while true;
do
if [ "${is_master_result/$expected_result}" = "$is_master_result" ] ; then
echo "Waiting for Mongod node to assume primary status..."
sleep 3
is_master_result=`mongo --host ${MONGODB1} < is_master_check`
echo ${is_master_result}
else
echo "Mongod node is now primary"
break;
fi
done
ping 127.0.0.1 > /dev/null