summaryrefslogtreecommitdiff
diff options
authorJuan L. Negron <juan.negron@canonical.com>2011-08-10 22:36:24 -0700
committerJuan L. Negron <juan.negron@canonical.com>2011-08-10 22:36:24 -0700
commita436f79bd0093c7079aa5babb218f7ddce2f26a6 (patch)
treee2a11799cbf1b1dff94a07cddd37205f9d0e89b8
Initial commit
-rwxr-xr-xhooks/database-relation-joined10
-rwxr-xr-xhooks/install72
-rwxr-xr-xhooks/replica-set-relation-changed87
-rwxr-xr-xhooks/replica-set-relation-joined10
-rwxr-xr-xhooks/start6
-rwxr-xr-xhooks/stop10
-rw-r--r--metadata.yaml21
7 files changed, 216 insertions, 0 deletions
diff --git a/hooks/database-relation-joined b/hooks/database-relation-joined
new file mode 100755
index 0000000..d6e930c
--- /dev/null
+++ b/hooks/database-relation-joined
@@ -0,0 +1,10 @@
+#!/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
+
+relation-set hostname=`hostname -f` replset=`facter replset-name`
+
+echo $ENSEMBLE_REMOTE_UNIT joined
diff --git a/hooks/install b/hooks/install
new file mode 100755
index 0000000..e4994df
--- /dev/null
+++ b/hooks/install
@@ -0,0 +1,72 @@
+#!/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
+
+############################################################################################################
+# Install some utility packages needed for installation
+############################################################################################################
+rm -f /etc/apt/sources.list.d/facter-plugins-ppa-oneiric.list
+echo deb http://ppa.launchpad.net/facter-plugins/ppa/ubuntu oneiric main >> /etc/apt/sources.list.d/facter-plugins-ppa-oneiric.list
+echo deb-src http://ppa.launchpad.net/facter-plugins/ppa/ubuntu oneiric main >> /etc/apt/sources.list.d/facter-plugins-ppa-oneiric.list
+apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B696B50DD8914A9290A4923D6383E098F7D4BE4B
+
+#apt-add-repository ppa:facter-plugins/ppa
+apt-get update
+DEBIAN_FRONTEND=noninteractive apt-get -y install facter facter-customfacts-plugin
+
+############################################################################################################
+# Set some variables that we'll need for later
+############################################################################################################
+
+DEFAULT_REPLSET_NAME="myset"
+HOSTNAME=`hostname -f`
+EPOCH=`date +%s`
+fact-add replset-name ${DEFAULT_REPLSET_NAME}
+fact-add install-time ${EPOCH}
+
+
+############################################################################################################
+# Install mongodb
+############################################################################################################
+
+DEBIAN_FRONTEND=noninteractive apt-get install -y mongodb
+
+
+############################################################################################################
+# Change the default mongodb configuration to bind to relfect that we are a master
+############################################################################################################
+
+sed -e "s/#master = true/master = true/" -e "s/bind_ip/#bind_ip/" -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".
+############################################################################################################
+sed -i -e "s/ -- / -- --replSet ${DEFAULT_REPLSET_NAME} /" /etc/init/mongodb.conf
+
+
+############################################################################################################
+# 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
+
+
+############################################################################################################
+# Initialize the replicaset
+############################################################################################################
+#sleep 5
+#mongo --eval "rs.initiate()"
+
+
+############################################################################################################
+# Register the port
+############################################################################################################
+[ -x /usr/bin/open-port ] && open-port 27017/TCP
diff --git a/hooks/replica-set-relation-changed b/hooks/replica-set-relation-changed
new file mode 100755
index 0000000..d32293f
--- /dev/null
+++ b/hooks/replica-set-relation-changed
@@ -0,0 +1,87 @@
+#!/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=`hostname -f`
+MY_REPLSET=`facter replset-name`
+MY_INSTALL_TIME=`facter install-time`
+
+MASTER_HOSTNAME=${MY_HOSTNAME}
+MASTER_REPLSET=${MY_REPLSET}
+MASTER_INSTALL_TIME=${MY_INSTALL_TIME}
+
+echo "My hosntmae: ${MY_HOSTNAME}"
+echo "My ReplSet: ${MY_REPLSET}"
+echo "My install time: ${MY_INSTALL_TIME}"
+
+############################################################################################################
+# 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.
+# Initialize the master node.
+# Add the other nodes to the master's replica set.
+############################################################################################################
+# Find the master ( lowest install time )
+for MEMBER in `relation-list`
+do
+ HOSTNAME=`relation-get hostname ${MEMBER}`
+ REPLSET=`relation-get replset ${MEMBER}`
+ INSTALL_TIME=`relation-get install-time ${MEMBER}`
+ [ ${INSTALL_TIME} -lt ${MASTER_INSTALL_TIME} ] && MASTER_INSTALL_TIME=${INSTALL_TIME}
+done
+
+echo "Master install-time: ${MASTER_INSTALL_TIME}"
+
+# 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}"
+
+# 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_INSTALL_TIME} -eq ${MY_INSTALL_TIME} ]; 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_TIME=`relation-get install-time ${MEMBER}`
+ if [ ${MASTER_INSTALL_TIME} -ne ${INSTALL_TIME} ]; then
+ if [ ${INSTALL_TIME} -eq ${MY_INSTALL_TIME} ]; then
+ mongo --eval "rs.add(\""${HOSTNAME}"\")"
+ else
+ mongo --host ${MASTER_HOSTNAME} --eval "rs.add(\""${HOSTNAME}"\")"
+ fi
+ fi
+done
+
+echo $ENSEMBLE_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
new file mode 100755
index 0000000..9431704
--- /dev/null
+++ b/hooks/replica-set-relation-joined
@@ -0,0 +1,10 @@
+#!/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
+
+relation-set hostname=`hostname -f` replset=`facter replset-name` install-time=`facter install-time`
+
+echo $ENSEMBLE_REMOTE_UNIT joined
diff --git a/hooks/start b/hooks/start
new file mode 100755
index 0000000..cd918d6
--- /dev/null
+++ b/hooks/start
@@ -0,0 +1,6 @@
+#!/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
new file mode 100755
index 0000000..5175b72
--- /dev/null
+++ b/hooks/stop
@@ -0,0 +1,10 @@
+#!/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
diff --git a/metadata.yaml b/metadata.yaml
new file mode 100644
index 0000000..e3e4ef3
--- /dev/null
+++ b/metadata.yaml
@@ -0,0 +1,21 @@
+ensemble: formula
+name: mongodb
+revision: 6
+summary: An object/document-oriented database (metapackage)
+description: |
+ MongoDB is a high-performance, open source, schema-free document-
+ oriented data store that's easy to deploy, manage and use. It's
+ network accessible, written in C++ and offers the following features :
+ * Collection oriented storage - easy storage of object- style data
+ * Full index support, including on inner objects * Query profiling
+ * Replication and fail-over support * Efficient storage of binary
+ data including large objects (e.g. videos) * Auto-sharding for
+ cloud-level scalability (Q209) High performance, scalability, and
+ reasonable depth of functionality are the goals for the project. This
+ is a metapackage that depends on all the mongodb parts.
+provides:
+ database:
+ interface: mongodb
+peers:
+ replica-set:
+ interface: mongodb-replica-set