diff options
| -rw-r--r-- | config.yaml | 8 | ||||
| -rwxr-xr-x | hooks/config-changed | 24 | ||||
| -rwxr-xr-x | hooks/install | 14 | ||||
| -rwxr-xr-x | hooks/replica-set-relation-changed | 36 | ||||
| -rwxr-xr-x | hooks/replica-set-relation-joined | 16 | ||||
| -rw-r--r-- | revision | 2 |
6 files changed, 61 insertions, 39 deletions
diff --git a/config.yaml b/config.yaml index 0db4fcf..d9685c7 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,8 @@ options: + default_port: + default: 27017 + type: string + description: Default MongoDB port replicaset: default: myset type: string @@ -7,6 +11,10 @@ options: default: yes type: string description: Replica Set Admin UI ( yes / no ) + web_amind_ui_port: + default: 28017 + type: string + description: Default port for the MongoDB web admin interface replicaset_master: default: auto type: string 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 + diff --git a/hooks/install b/hooks/install index 2c3d66a..8c208e3 100755 --- a/hooks/install +++ b/hooks/install @@ -5,17 +5,12 @@ set -ux ############################################################################################################ -# Install some utility packages needed for installation -############################################################################################################ -DEBIAN_FRONTEND=noninteractive apt-get -y install facter facter-customfacts-plugin - -############################################################################################################ # Set some variables that we'll need for later ############################################################################################################ DEFAULT_REPLSET_NAME=`config-get replicaset` HOSTNAME=`hostname -f` EPOCH=`date +%s` -fact-add install-time ${EPOCH} +INSTALL_ORDER=$(echo ${JUJU_UNIT_NAME} | awk -F/ '{ print $2 }') WEB_ADMIN_UI=`config-get web_admin_ui` REPLICASET_MASTER=`config-get replicaset_master` @@ -61,6 +56,13 @@ service mongodb start # 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 diff --git a/hooks/replica-set-relation-changed b/hooks/replica-set-relation-changed index b32aed1..0f53425 100755 --- a/hooks/replica-set-relation-changed +++ b/hooks/replica-set-relation-changed @@ -13,7 +13,7 @@ set -ux ############################################################################################################ MY_HOSTNAME=`hostname -f` MY_REPLSET=`config-get replicaset` -MY_INSTALL_TIME=`facter install-time` +MY_INSTALL_ORDER=$(echo ${JUJU_UNIT_NAME} | awk -F/ '{ print $2 }') MY_REPLICASET_MASTER=`config-get replicaset_master` @@ -27,48 +27,34 @@ fi MASTER_HOSTNAME=${MY_HOSTNAME} MASTER_REPLSET=${MY_REPLSET} -MASTER_INSTALL_TIME=${MY_INSTALL_TIME} +MASTER_INSTALL_ORDER=${MY_INSTALL_ORDER} echo "My hosntmae: ${MY_HOSTNAME}" echo "My ReplSet: ${MY_REPLSET}" -echo "My install time: ${MY_INSTALL_TIME}" +echo "My install order: ${MY_INSTALL_ORDER}" ############################################################################################################ -# Here we need to find out which is the first node ( we record the install time ). -# The one with the lowest install time is the master. +# Here we need to find out which is the first node ( we record the install order ). +# The one with the lowest order time is the master. # Initialize the master node. # Add the other nodes to the master's replica set. ############################################################################################################ -# Find the master ( lowest install time ) +# Find the master ( lowest install order ) for MEMBER in `relation-list` do HOSTNAME=`relation-get hostname ${MEMBER}` REPLSET=`relation-get replset ${MEMBER}` - INSTALL_TIME=`relation-get install-time ${MEMBER}` - if [ ${INSTALL_TIME} -lt ${MASTER_INSTALL_TIME} ];then + INSTALL_ORDER=`relation-get install-order ${MEMBER}` + if [ ${INSTALL_ORDER} -lt ${MASTER_INSTALL_ORDER} ];then MASTER_HOSTNAME=${HOSTNAME} MASTER_REPLSET=${REPLSET} - MASTER_INSTALL_TIME=${INSTALL_TIME} + MASTER_INSTALL_ORDER=${INSTALL_ORDER} fi done -echo "Master host: ${MASTER_HOSTNAME}" - -# We should now have the lowest member of this relationship. Let's get all of the information about it. -#for MEMBER in `relation-list` -#do -# HOSTNAME=`relation-get hostname ${MEMBER}` -# REPLSET=`relation-get replset ${MEMBER}` -# INSTALL_TIME=`relation-get install-time ${MEMBER}` -# if [ ${INSTALL_TIME} -eq ${MASTER_INSTALL_TIME} ]; then -# MASTER_HOSTNAME=${HOSTNAME} -# MASTER_REPLSET=${REPLSET} -# fi -#done - echo "Master Hostname: ${MASTER_HOSTNAME}" echo "Master ReplSet: ${MASTER_REPLSET}" -echo "Master install time: ${MASTER_INSTALL_TIME}" +echo "Master install order: ${MASTER_INSTALL_ORDER}" # We should now have all the information about the master node. # If the node has already been initialized, it will just inform you @@ -84,7 +70,7 @@ for MEMBER in `relation-list` do HOSTNAME=`relation-get hostname ${MEMBER}` REPLSET=`relation-get replset ${MEMBER}` - INSTALL_TIME=`relation-get install-time ${MEMBER}` + INSTALL_ORDER=`relation-get install-order ${MEMBER}` if [ "${MASTER_HOSTNAME}" != "${HOSTNAME}" ]; then if [ "${HOSTNAME}" == "${MY_HOSTNAME}" ]; then mongo --eval "rs.add(\""${HOSTNAME}"\")" diff --git a/hooks/replica-set-relation-joined b/hooks/replica-set-relation-joined index 6285ac4..317673c 100755 --- a/hooks/replica-set-relation-joined +++ b/hooks/replica-set-relation-joined @@ -6,6 +6,7 @@ set -ux DEFAULT_REPLSET_NAME=`config-get replicaset` +INSTALL_ORDER=$(echo ${JUJU_UNIT_NAME} | awk -F/ '{ print $2 }') ############################################################################################################ # Reconfigure the upstart script to include the replica-set option. @@ -13,13 +14,14 @@ DEFAULT_REPLSET_NAME=`config-get replicaset` # Replica sets can only talk to each other if they all belong to the same # set. In our case, we have defaulted to "myset". ############################################################################################################ +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 -grep "${DEFAULT_REPLSET_NAME}" /etc/init/mongodb.conf || 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 - -relation-set hostname=`hostname -f` replset=${DEFAULT_REPLSET_NAME} install-time=`facter install-time` +relation-set hostname=`hostname -f` replset=${DEFAULT_REPLSET_NAME} install-order=${INSTALL_ORDER} echo $JUJU_REMOTE_UNIT joined @@ -1 +1 @@ -17 +22 |
