~george-edison55/charms/oneiric/thinkup/update-to-1-0-2

« back to all changes in this revision

Viewing changes to hooks/db-relation-changed

  • Committer: Nathan Osman
  • Date: 2011-11-19 05:59:33 UTC
  • Revision ID: admin@quickmediasolutions.com-20111119055933-mv36jmb3qxvk889w
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
 
3
 
set -e
4
 
 
5
 
# Retrieve this machine's hostname
6
 
HOSTNAME=`unit-get public-address`
7
 
juju-log "Hostname: $HOSTNAME"
8
 
 
9
 
# Retrieve the settings from the database
10
 
juju-log "Retrieving database relationship"
11
 
DATABASE=`relation-get database`
12
 
 
13
 
if [ -z "$DATABASE" ] ; then
14
 
    juju-log "No database relationship set"
15
 
    exit 0
16
 
fi
17
 
 
18
 
# Fetch the database configuration
19
 
juju-log "Retrieving database configuration"
20
 
DB_USER=`relation-get user`
21
 
DB_PASS=`relation-get password`
22
 
DB_HOST=`relation-get private-address`
23
 
 
24
 
# Update the data in the configuration file
25
 
juju-log "Updating configuration file"
26
 
update_thinkup_config <<EOD
27
 
db_host=$DB_HOST
28
 
db_user=$DB_USER
29
 
db_password=$DB_PASS
30
 
db_name=$DATABASE
31
 
EOD
32
 
 
33
 
# Execute the SQL that creates the tables
34
 
juju-log "Creating database tables"
35
 
mysql -u$DB_USER -p$DB_PASS -h$DB_HOST $DATABASE < /var/www/install/sql/build-db_mysql.sql