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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh

#set -ux

user=`relation-get user`
password=`relation-get password`
host=`relation-get private-address`
database=`config-get website-database`
if [ -z "$host" ] || [ -z "$user" ]; then
	juju-log "Waiting for complete setup"
	exit 0
fi

# Build config file to hold configuration options

juju-log "Building config file for $host"
cat > "config/$host" <<EOF
#!/bin/sh

server_name=${JUJU_REMOTE_UNIT%%/*}
server_user=${user}
server_pass=${password}
server_db=${database}
EOF
#

cat > "config/mysql" <<EOF
server_ip=${host}
EOF
#

juju-log "Building $database database on $host"

mysqladmin -h $host -u $user --password=$password create "$database"
mysql -h $host -u $user --password=$password $database < ./config/mysql_conf


cp ./config/* /var/webconfig

juju-log "Exposing apache2 service"
open-port 80/tcp