diff options
Diffstat (limited to 'hooks')
| -rwxr-xr-x | hooks/config-changed | 25 | ||||
| -rwxr-xr-x | hooks/database-relation-joined | 13 | ||||
| -rwxr-xr-x | hooks/install | 83 | ||||
| -rwxr-xr-x | hooks/replica-set-relation-changed | 93 | ||||
| -rwxr-xr-x | hooks/replica-set-relation-joined | 28 | ||||
| -rwxr-xr-x | hooks/start | 6 | ||||
| -rwxr-xr-x | hooks/stop | 10 | 
7 files changed, 0 insertions, 258 deletions
diff --git a/hooks/config-changed b/hooks/config-changed deleted file mode 100755 index df92ffb..0000000 --- a/hooks/config-changed +++ /dev/null @@ -1,25 +0,0 @@ -#!/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` -HOSTNAME=`unit-get public-address` - -############################################################################################################ -# 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/database-relation-joined b/hooks/database-relation-joined deleted file mode 100755 index 23ead04..0000000 --- a/hooks/database-relation-joined +++ /dev/null @@ -1,13 +0,0 @@ -#!/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 - -HOSTNAME=`unit-get public-address` -REPLICASET=`config-get replicaset` - -relation-set hostname=${HOSTNAME} replset=${REPLICASET} - -echo $JUJU_REMOTE_UNIT joined diff --git a/hooks/install b/hooks/install deleted file mode 100755 index b0bf7c2..0000000 --- a/hooks/install +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash -# Here do anything needed to install the service -# i.e. apt-get install -y foo or bzr branch http://myserver/mycode /srv/webroot - -set -ux - -############################################################################################################ -# Set some variables that we'll need for later -############################################################################################################ -DEFAULT_REPLSET_NAME=`config-get replicaset` -#HOSTNAME=`hostname -f` -HOSTNAME=`unit-get public-address` -EPOCH=`date +%s` -INSTALL_ORDER=$(echo ${JUJU_UNIT_NAME} | awk -F/ '{ print $2 }') -WEB_ADMIN_UI=`config-get web_admin_ui` -REPLICASET_MASTER=`config-get replicaset_master` -DEFAULT_PORT=`config-get default_port` - - -############################################################################################################ -# Install mongodb -############################################################################################################ -DEBIAN_FRONTEND=noninteractive apt-get install -y mongodb - - -############################################################################################################ -# Change the default mongodb configuration -############################################################################################################ -sed -e "s/#master = true/master = true/" \ - -e "s/bind_ip/#bind_ip/" \ - -e "s/#port = 27017/port = ${DEFAULT_PORT}/" \ - -i /etc/mongodb.conf - - -############################################################################################################ -# Reconfigure the upstart script to include the replica-set option. -# We'll need this so, when we add nodes, they can all talk to each other. -# Replica sets can only talk to each other if they all belong to the same -# set. In our case, we have defaulted to "myset". -############################################################################################################ -# Web Admin UI -if [ "$WEB_ADMIN_UI" == "yes" ]; then -	sed -i -e "s/ -- / -- --rest /" /etc/init/mongodb.conf -fi - -if [ "${REPLICASET_MASTER}" != "auto" ]; then -	sed -i -e "s/ -- / -- --replSet ${DEFAULT_REPLSET_NAME} /" /etc/init/mongodb.conf -fi - - -############################################################################################################ -# stop then start ( *** not restart **** ) mongodb so we can finish the configuration -############################################################################################################ -service mongodb stop -# There is a bug in the upstart script that leaves a lock file orphaned.... Let's wipe that file out -rm -f /var/lib/mongodb/mongod.lock -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 - - -############################################################################################################ -# Register the port -############################################################################################################ -[ -x /usr/bin/open-port ] && open-port ${DEFAULT_PORT}/TCP -if [ "$WEB_ADMIN_UI" == "yes" ]; then - [ -x /usr/bin/open-port ] && open-port $((${DEFAULT_PORT} + 1000))/TCP -fi - -exit 0 diff --git a/hooks/replica-set-relation-changed b/hooks/replica-set-relation-changed deleted file mode 100755 index d0b41bc..0000000 --- a/hooks/replica-set-relation-changed +++ /dev/null @@ -1,93 +0,0 @@ -#!/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, modified, or broken -# This script should be idempotent. - -############################################################################################################ -# Set debugging information -############################################################################################################ -set -ux - -############################################################################################################ -# Set some global variables -############################################################################################################ -MY_HOSTNAME=`unit-get public-address` -MY_REPLSET=`config-get replicaset` -MY_INSTALL_ORDER=$(echo ${JUJU_UNIT_NAME} | awk -F/ '{ print $2 }') -MY_REPLICASET_MASTER=`config-get replicaset_master` - - -############################################################################################################ -# If we are joining an existing replicaset cluster, just join and leave. -############################################################################################################ -if [ "${MY_REPLICASET_MASTER}" != "auto" ]; then -	mongo --host ${MY_REPLICASET_MASTER} --eval "rs.add(\""${MY_HOSTNAME}"\")" -	exit $? -fi - -MASTER_HOSTNAME=${MY_HOSTNAME} -MASTER_REPLSET=${MY_REPLSET} -MASTER_INSTALL_ORDER=${MY_INSTALL_ORDER} - -echo "My hosntmae: ${MY_HOSTNAME}" -echo "My ReplSet: ${MY_REPLSET}" -echo "My install order: ${MY_INSTALL_ORDER}" - -############################################################################################################ -# 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 order ) -for MEMBER in `relation-list` -do - HOSTNAME=`relation-get hostname ${MEMBER}` - REPLSET=`relation-get replset ${MEMBER}` - INSTALL_ORDER=`relation-get install-order ${MEMBER}` - if [ ${INSTALL_ORDER} -lt ${MASTER_INSTALL_ORDER} ];then - MASTER_HOSTNAME=${HOSTNAME} - MASTER_REPLSET=${REPLSET} - MASTER_INSTALL_ORDER=${INSTALL_ORDER} - fi -done - -echo "Master Hostname: ${MASTER_HOSTNAME}" -echo "Master ReplSet: ${MASTER_REPLSET}" -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 -# about it with no other consequence. -if [ "${MASTER_HOSTNAME}" == "${MY_HOSTNAME}" ]; then - mongo --eval "rs.initiate()" -else - mongo --host ${MASTER_HOSTNAME} --eval "rs.initiate()" -fi - -# Now we need to add the rest of nodes to the replica set -for MEMBER in `relation-list` -do - HOSTNAME=`relation-get hostname ${MEMBER}` - REPLSET=`relation-get replset ${MEMBER}` - INSTALL_ORDER=`relation-get install-order ${MEMBER}` - if [ "${MASTER_HOSTNAME}" != "${HOSTNAME}" ]; then - if [ "${HOSTNAME}" == "${MY_HOSTNAME}" ]; then - mongo --eval "rs.add(\""${HOSTNAME}"\")" - else - mongo --host ${MASTER_HOSTNAME} --eval "rs.add(\""${HOSTNAME}"\")" - fi - fi -done - -# Add myself to the replicaset if needed -if [ "${MASTER_HOSTNAME}" != "${MY_HOSTNAME}" ]; then - mongo --host ${MASTER_HOSTNAME} --eval "rs.add(\""${MY_HOSTNAME}"\")" -fi - - -echo $JUJU_REMOTE_UNIT modified its settings -echo Relation settings: -relation-get -echo Relation members: -relation-list diff --git a/hooks/replica-set-relation-joined b/hooks/replica-set-relation-joined deleted file mode 100755 index ecf1e71..0000000 --- a/hooks/replica-set-relation-joined +++ /dev/null @@ -1,28 +0,0 @@ -#!/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` -INSTALL_ORDER=$(echo ${JUJU_UNIT_NAME} | awk -F/ '{ print $2 }') -HOSTNAME=`unit-get public-address` - -############################################################################################################ -# Reconfigure the upstart script to include the replica-set option. -# We'll need this so, when we add nodes, they can all talk to each other. -# 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 - -relation-set hostname=${HOSTNAME} replset=${DEFAULT_REPLSET_NAME} install-order=${INSTALL_ORDER} - -echo $JUJU_REMOTE_UNIT joined diff --git a/hooks/start b/hooks/start deleted file mode 100755 index cd918d6..0000000 --- a/hooks/start +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# Here put anything that is needed to start the service. -# Note that currently this is run directly after install -# i.e. 'service apache2 start' - -service mongodb status && service mongodb restart || service mongodb start diff --git a/hooks/stop b/hooks/stop deleted file mode 100755 index 5175b72..0000000 --- a/hooks/stop +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# This will be run when the service is being torn down, allowing you to disable -# it in various ways.. -# For example, if your web app uses a text file to signal to the load balancer -# that it is live... you could remove it and sleep for a bit to allow the load -# balancer to stop sending traffic. -# rm /srv/webroot/server-live.txt && sleep 30 - -service mongodb stop -rm -f /var/lib/mongodb/mongod.lock  | 
