~jorge/charms/precise/lamp/readme-fixes

« back to all changes in this revision

Viewing changes to hooks/shared-db-relation-changed

  • Committer: Victor Palau
  • Date: 2012-10-02 13:23:57 UTC
  • Revision ID: vtuson@gmail.com-20121002132357-3zi9hx2fgnjoag33
changed the charm to use mysql-shared

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
juju-log "lamp - shared-db: Relation CHANGED"
 
4
myuser=`config-get database-user`
 
5
mydatabase=`config-get website-database`
 
6
 
 
7
#get informations from db
 
8
remote_host=`relation-get private-address`
 
9
password=`relation-get password`
 
10
juju-log "remote host is $remote_host"
 
11
if [ -z "$remote_host" ] || [ -z "$password" ]; then
 
12
        juju-log "Waiting for complete setup"
 
13
        exit 0
 
14
fi
 
15
 
 
16
# Build config file to hold configuration options
 
17
juju-log "Building config file for $host"
 
18
cat > "config/$remote_host" <<EOF
 
19
#!/bin/sh
 
20
 
 
21
server_name=${JUJU_REMOTE_UNIT%%/*}
 
22
server_user=${myuser}
 
23
server_pass=${password}
 
24
server_db=${mydatabase}
 
25
EOF
 
26
#
 
27
#creating file pointing to last configuration 
 
28
cat > "config/mysql" <<EOF
 
29
server_ip=${remote_host}
 
30
EOF
 
31
#
 
32
 
 
33
#building the database
 
34
juju-log "Building $database database on $host"
 
35
mysql -h $remote_host -u $myuser --password=$password $mydatabase < ./config/mysql_conf
 
36
 
 
37
#setting up configuration files to be accessible by apache process
 
38
cp ./config/* /var/webconfig
 
39
chown -R www-data:www-data ./config
 
40
chown -R www-data:www-data /var/webconfig
 
41
chmod 640 ./config/*
 
42
chmod 640 /var/webconfig/*