Merge lp:~kim0/pyjuju/fix-mysql-example-formula-publish-details-precreated-databases into lp:pyjuju

Proposed by Ahmed Kamal
Status: Merged
Approved by: Gustavo Niemeyer
Approved revision: 241
Merged at revision: 244
Proposed branch: lp:~kim0/pyjuju/fix-mysql-example-formula-publish-details-precreated-databases
Merge into: lp:pyjuju
Diff against target: 41 lines (+12/-6)
1 file modified
examples/mysql/hooks/db-relation-joined (+12/-6)
To merge this branch: bzr merge lp:~kim0/pyjuju/fix-mysql-example-formula-publish-details-precreated-databases
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Approve
Review via email: mp+63426@code.launchpad.net

Description of the change

Fixing for formula for saving service DB passwords, and publishing them to new service units

To post a comment you must log in.
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

This looks like a good interim solution, thanks!

The proper way is actually to use a database named after the relation id,
and then create a new database on every new relation id we get. The
problem is that we currently don't offer such a relation id for the hooks,
so this will do for now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/mysql/hooks/db-relation-joined'
2--- examples/mysql/hooks/db-relation-joined 2011-05-03 08:54:13 +0000
3+++ examples/mysql/hooks/db-relation-joined 2011-06-03 20:01:15 +0000
4@@ -2,6 +2,11 @@
5
6 set -eu # -x for verbose logging to ensemble debug-log
7
8+# XXX The local hostname should be provided by Ensemble itself in a
9+# future release, so as to remove the dependency of the formula on the
10+# cloud provider (EC2 in this case)
11+hostname=`curl http://169.254.169.254/latest/meta-data/local-hostname`
12+
13 # Get the mysql password that was generated by the install hook
14 password=`cat /var/lib/ensemble/mysql.passwd`
15
16@@ -13,18 +18,19 @@
17 existing_databases=`mysql --password="$password" --silent --execute 'show databases'`
18 for db in $existing_databases; do
19 if [ "$db" = "$service" ] ; then
20- ensemble-log "Database already exists, exiting"
21+ ensemble-log "Database already exists, publishing details and exiting"
22+ service_password=`cat /var/lib/ensemble/$service.passwd`
23+ # Save these settings on the relation; this will trigger the remote
24+ # service unit
25+ relation-set database="$service" user="$service" password="$service_password" host="$hostname"
26 exit 0 # database already exists
27 fi
28 done
29
30 # Generate a strong password for the database, using /dev/urandom
31 service_password=`pwgen 10 1`
32-
33-# XXX The local hostname should be provided by Ensemble itself in a
34-# future release, so as to remove the dependency of the formula on the
35-# cloud provider (EC2 in this case)
36-hostname=`curl http://169.254.169.254/latest/meta-data/local-hostname`
37+# Store service password, new service units of same service would need it
38+echo $service_password >> /var/lib/ensemble/$service.passwd
39
40 # Create new database and corresponding security settings
41 ensemble-log "Creating new database and corresponding security settings"

Subscribers

People subscribed via source and target branches

to status/vote changes: