Skip to content

Commit

Permalink
Build rs.conf with fqdn members
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgough committed Sep 13, 2017
1 parent a90882b commit 57b8ec4
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions 3.2/root/usr/share/container-scripts/mongodb/init-replset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function initiate() {

info "Waiting for PRIMARY status ..."
mongo --eval "while (!rs.isMaster().ismaster) { sleep(100); }" --quiet

mongo_create_admin
#[[ -v CREATE_USER ]] && mongo_create_user "-u admin -p ${MONGODB_ADMIN_PASSWORD}"

Expand All @@ -51,11 +51,11 @@ function add_member() {

# add wait for the mongodb-1 service
wait_for_service mongodb-1
# wait for mongodb daemon to come up

# wait for mongodb daemon to come up
wait_for_mongo_up mongodb-1


local host="$1"
info "Adding ${host} to replica set ..."

Expand All @@ -73,6 +73,18 @@ function add_member() {
info "Successfully joined replica set"
}

function get_fqdn_hostname() {

local short_host="$1"

namespace=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)

local fqdn=$short_host.$namespace

echo $fqdn

}

info "Waiting for local MongoDB to accept connections ..."
wait_for_mongo_up &>/dev/null

Expand All @@ -89,12 +101,12 @@ fi
# "mongodb-1" -> "1"
# "mongodb-2" -> "2"
readonly MEMBER_ID="${MEMBER_HOST##*-}"

fqdn=$(get_fqdn_hostname "${MEMBER_HOST}")
# Initialize replica set only if we're the first member
if [ "${MEMBER_ID}" = '1' ]; then
initiate "${MEMBER_HOST}"
initiate "${fqdn}"
else
add_member "${MEMBER_HOST}"
add_member "${fqdn}"
fi

>/tmp/initialized

0 comments on commit 57b8ec4

Please sign in to comment.