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
=== modified file 'examples/mysql/hooks/db-relation-joined'
--- examples/mysql/hooks/db-relation-joined 2011-05-03 08:54:13 +0000
+++ examples/mysql/hooks/db-relation-joined 2011-06-03 20:01:15 +0000
@@ -2,6 +2,11 @@
22
3set -eu # -x for verbose logging to ensemble debug-log3set -eu # -x for verbose logging to ensemble debug-log
44
5# XXX The local hostname should be provided by Ensemble itself in a
6# future release, so as to remove the dependency of the formula on the
7# cloud provider (EC2 in this case)
8hostname=`curl http://169.254.169.254/latest/meta-data/local-hostname`
9
5# Get the mysql password that was generated by the install hook10# Get the mysql password that was generated by the install hook
6password=`cat /var/lib/ensemble/mysql.passwd`11password=`cat /var/lib/ensemble/mysql.passwd`
712
@@ -13,18 +18,19 @@
13existing_databases=`mysql --password="$password" --silent --execute 'show databases'`18existing_databases=`mysql --password="$password" --silent --execute 'show databases'`
14for db in $existing_databases; do19for db in $existing_databases; do
15 if [ "$db" = "$service" ] ; then20 if [ "$db" = "$service" ] ; then
16 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"
17 exit 0 # database already exists26 exit 0 # database already exists
18 fi27 fi
19done28done
2029
21# Generate a strong password for the database, using /dev/urandom30# Generate a strong password for the database, using /dev/urandom
22service_password=`pwgen 10 1`31service_password=`pwgen 10 1`
2332# Store service password, new service units of same service would need it
24# XXX The local hostname should be provided by Ensemble itself in a33echo $service_password >> /var/lib/ensemble/$service.passwd
25# future release, so as to remove the dependency of the formula on the
26# cloud provider (EC2 in this case)
27hostname=`curl http://169.254.169.254/latest/meta-data/local-hostname`
2834
29# Create new database and corresponding security settings35# Create new database and corresponding security settings
30ensemble-log "Creating new database and corresponding security settings"36ensemble-log "Creating new database and corresponding security settings"

Subscribers

People subscribed via source and target branches

to status/vote changes: