From 64eb056811c8a8ee798ea43a7ff1251f3a810976 Mon Sep 17 00:00:00 2001 From: "Juan L. Negron" Date: Wed, 14 Dec 2011 14:02:17 -0800 Subject: Added config-changed hook to better handle replica_set_master variable --- hooks/config-changed | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 hooks/config-changed (limited to 'hooks/config-changed') diff --git a/hooks/config-changed b/hooks/config-changed new file mode 100755 index 0000000..b678ceb --- /dev/null +++ b/hooks/config-changed @@ -0,0 +1,24 @@ +#!/bin/bash +# This must be renamed to the name of the relation. The goal here is to +# affect any change needed by relationships being formed +# This script should be idempotent. + +set -ux + +DEFAULT_REPLSET_NAME=`config-get replicaset` +REPLICASET_MASTER=`config-get replicaset_master` + +############################################################################################################ +# Are we connecting to an existing replica set? +############################################################################################################ +if [ "${REPLICASET_MASTER}" != "auto" ]; then + grep "${DEFAULT_REPLSET_NAME}" /etc/init/mongodb.conf + if [ $? -ne 0 ];then + sed -i -e "s/ -- / -- --replSet ${DEFAULT_REPLSET_NAME} /" /etc/init/mongodb.conf + service mongodb stop + rm -f /var/lib/mongodb/mongod.lock + service mongodb start + fi + mongo --host ${REPLICASET_MASTER} --eval "rs.add(\""${HOSTNAME}"\")" +fi + -- cgit v1.2.3