Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Use latest Giddyup and fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
galal-hussein committed Jan 4, 2017
1 parent df516fc commit b195b4f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
4 changes: 1 addition & 3 deletions MongoDB/0.1.0/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mongo-cluster:
restart: always
environment:
MONGO_SERVICE_NAME: mongo-cluster
tty: true
entrypoint: /opt/rancher/bin/entrypoint.sh
command:
- --replSet
Expand All @@ -16,11 +15,10 @@ mongo-cluster:
- mongo-base
mongo-base:
restart: always
tty: true
labels:
io.rancher.container.hostname_override: container_name
io.rancher.container.start_once: true
image: rancher/mongodb-conf:v0.1.0
image: rancher/mongodb-conf:v0.2.0
stdin_open: true
entrypoint: /bin/true
mongo-datavolume:
Expand Down
19 changes: 6 additions & 13 deletions MongoDB/containers/0.1.0/mongodb-config/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
FROM alpine:3.1
MAINTAINER Hussein Galal

# install giddyup
RUN apk add -U curl \
&& mkdir -p /opt/rancher/bin \
&& curl -L https://github.com/cloudnautique/giddyup/releases/download/v0.14.0/giddyup -o /opt/rancher/bin/giddyup \
&& chmod u+x /opt/rancher/bin/*

ADD ./*.sh /opt/rancher/bin/
RUN chmod u+x /opt/rancher/bin/*.sh

# install dig and jq
RUN apk add -U alpine-sdk \
&& curl ftp://ftp.isc.org/isc/bind9/9.10.2/bind-9.10.2.tar.gz|tar -xzv \
&& cd bind-9.10.2 \
&& CFLAGS="-static" ./configure --without-openssl --disable-symtable \
&& make \
&& cp ./bin/dig/dig /opt/rancher/bin/ \
&& curl -L https://github.com/cloudnautique/giddyup/releases/download/v0.8.0/giddyup -o /opt/rancher/bin/giddyup \
&& chmod u+x /opt/rancher/bin/* \
&& apk del alpine-sdk \
&& rm -rf /var/cache/apk/* \
&& rm -rf /bind-9.10.2/

VOLUME /opt/rancher/bin
15 changes: 9 additions & 6 deletions MongoDB/containers/0.1.0/mongodb-config/connect.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/bin/bash
DIG=/opt/rancher/bin/dig

set -x

GIDDYUP=/opt/rancher/bin/giddyup

function cluster_init {
sleep 10
MYIP=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | sed -n 2p)
$DIG A $MONGO_SERVICE_NAME +short > ips.tmp
MYIP=$($GIDDYUP ip myip)
$GIDDYUP ip stringify --delimiter " " > ips.tmp
mongo --eval "printjson(rs.initiate())"
for member in $(cat ips.tmp); do
if [ $member != $MYIP ]; then
if [ "$member" != "$MYIP" ]; then
mongo --eval "printjson(rs.add('$member:27017'))"
sleep 5
fi
Expand All @@ -16,7 +19,7 @@ function cluster_init {
}

function find_master {
$DIG A $MONGO_SERVICE_NAME +short > ips.tmp
$GIDDYUP ip stringify --delimiter " " > ips.tmp
for IP in $(cat ips.tmp); do
IS_MASTER=`mongo --host $IP --eval "printjson(db.isMaster())" | grep 'ismaster'`
if echo $IS_MASTER | grep "true"; then
Expand All @@ -27,7 +30,7 @@ function find_master {
}
# Script starts here
# wait for mongo to start
while [ `$DIG A $MONGO_SERVICE_NAME +short | wc -l` -lt 3 ]; do
while [ `$GIDDYUP ip stringify --delimiter " " | wc -w` -lt 3 ]; do
echo 'mongo instances are less than 3.. waiting!'
sleep 5
done
Expand Down
4 changes: 2 additions & 2 deletions MongoDB/containers/0.1.0/mongodb-config/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -x

# Check for lowest ID
sleep 10
/opt/rancher/bin/giddyup leader check
Expand All @@ -10,7 +12,6 @@ else

# Run the scaling script
/opt/rancher/bin/scaling.sh &

# Start mongodb
if [ $? -ne 0 ]
then
Expand All @@ -33,7 +34,6 @@ if [ "$1" = 'mongod' ]; then

exec gosu mongodb "$@"
fi

exec "$@"

fi
11 changes: 7 additions & 4 deletions MongoDB/containers/0.1.0/mongodb-config/scaling.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash

set -x

sleep 5
DIG=/opt/rancher/bin/dig
GIDDYUP=/opt/rancher/bin/giddyup

function scaleup {
MYIP=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | sed -n 2p)
$DIG A $MONGO_SERVICE_NAME +short > ips.tmp
MYIP=$($GIDDYUP ip myip)
$GIDDYUP ip stringify --delimiter " " > ips.tmp
for IP in $(cat ips.tmp); do
IS_MASTER=$(mongo --host $IP --eval "printjson(db.isMaster())" | grep 'ismaster')
if echo $IS_MASTER | grep "true"; then
Expand All @@ -16,6 +19,6 @@ function scaleup {
}

# Script starts here
if [ $($DIG A $MONGO_SERVICE_NAME +short | wc -l) -gt 3 ]; then
if [ $($GIDDYUP ip stringify --delimiter " " | wc -w) -gt 3 ]; then
scaleup
fi

0 comments on commit b195b4f

Please sign in to comment.