~clint-fewbar/charms/precise/moodle/slow

« back to all changes in this revision

Viewing changes to hooks/db-relation-changed

  • Committer: Ryan Kather
  • Date: 2012-03-23 02:59:45 UTC
  • Revision ID: rkather@missionpenguin.com-20120323025945-gaf9h1t7k8hbr8pf
db relation improvements and install fixup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
 
3
 
# Verbose Logging for debug-log
4
 
set -eux
5
 
 
6
 
# Retrieve DB Settings
7
 
juju-log "Retrieving Database Relationship"
8
 
DB_NAME=`relation-get database`
9
 
DB_USER=`relation-get user`
10
 
DB_PASS=`relation-get password`
11
 
DB_HOST=`relation-get private-address`
12
 
HOST=`unit-get public-address`
13
 
 
14
 
# Fail on Missing Data
15
 
if [[ -z $DB_NAME || -z $DB_USER || -z $DB_PASS || -z $DB_HOST ]]; then
16
 
    juju-log "No Database Relationship Set"
 
1
#!/bin/bash
 
2
 
 
3
# Juju Debug-Logging
 
4
set -eu
 
5
 
 
6
juju-log "Begin Config now that we have DB"
 
7
HOSTNAME=`unit-get public-address`
 
8
LOCALNAME=`hostname -f`
 
9
juju-log "External Host: $HOSTNAME"
 
10
 
 
11
DATABASE=`relation-get database`
 
12
USER=`relation-get user`
 
13
PASSWORD=`relation-get password`
 
14
DBHOST=`relation-get private-address`
 
15
 
 
16
# Exit if no Database
 
17
if [ -z "$DATABASE" ]; then
17
18
    exit 0
18
19
fi
19
20
 
20
 
# Pulling Values from config.yaml
21
 
ADMINUSER=`config-get adminuser`
22
 
ADMINPASS=`config-get adminpass`
23
 
CHMOD=`config-get chmod`
24
 
DATAROOT=`config-get dataroot`
25
 
DBTYPE=`config-get dbtype`
26
 
FULLNAME=`config-get fullname`
27
 
SHORTNAME=`config-get shortname`
 
21
juju-log "Check if DB Already Exists"
 
22
CUR_TABLE_COUNT=`mysql -h $DBHOST -u $USER -p $PASSWORD -Nse "SELECT count(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=\"$DATABASE\""`
 
23
 
 
24
if [ $CUR_TABLE_COUNT -eq 0 ]; then
 
25
    # Pulling Values from config.yaml Directives 
 
26
    ADMINUSER=`config-get adminuser`
 
27
    ADMINPASS=`config-get adminpass`
 
28
    CHMOD=`config-get chmod`
 
29
    DATAROOT=`config-get dataroot`
 
30
    DBTYPE=`config-get dbtype`
 
31
    FULLNAME=`config-get fullname`
 
32
    SHORTNAME=`config-get shortname`
 
33
else
 
34
    juju-log "I am part of an existing install"
 
35
fi
28
36
 
29
37
# Perform the Site Configuration/DB Init
30
38
juju-log "Passing Config Options to Moodle"
31
 
/usr/local/share/moodle/admin/cli/install.php --wwwroot=`unit-get public-address` --dataroot=$DATAROOT --dbtype=$DBTYPE --dbhost=$DB_HOST --dbname=$DBNAME --dbuser=$DB_USER --dbpass=$DB_PASS --non-interactive --agree-license --chmod=$CHMOD --sitename --adminuser=$ADMINUSER --adminpass=$ADMINPASS
 
39
/usr/local/share/moodle/admin/cli/install.php --wwwroot=http://`unit-get public-address` --dataroot=$DATAROOT --dbtype=$DBTYPE --dbhost=$DBHOST --dbname=$DATABASE --dbuser=$USER --dbpass=$PASSWORD --non-interactive --agree-license --chmod=$CHMOD --shortname=$SHORTNAME --fullname="$FULLNAME" --adminuser=$ADMINUSER --adminpass=$ADMINPASS
32
40
 
33
41
# Write Apache Config
34
42
APACHE_CONF="/etc/apache2/sites-available/$HOST"
39
47
  DocumentRoot /usr/local/share/moodle/
40
48
  <Directory /usr/local/share/moodle/>
41
49
    Options Indexes FollowSymLinks MultiViews
 
50
    DirectoryIndex index.php index.html index.htm
42
51
    AllowOverride None
43
52
    Order allow,deny
44
53
    allow from all
57
66
 
58
67
</VirtualHost>
59
68
EOF
60
 
chmod 0644 $APACHE_CONF
61
 
 
62
 
# Disabling the Default Site and Enabling Moodle's
63
 
a2dissite default
64
 
a2ensite $HOST
65
 
 
66
 
# Restaritng Apache to Notice the Change
67
 
juju-log "Restarting Apache2 Service"
 
69
 
 
70
juju-log "Restarting Apache"
68
71
service apache2 restart
 
72
 
 
73
# Make port 80 available
 
74
juju-log "Opening port 80"
 
75
open-port 80/tcp