~imbrandon/+junk/omg-bzr

« back to all changes in this revision

Viewing changes to hooks/db-relation-changed

  • Committer: Brandon Holtsclaw
  • Date: 2012-05-30 07:31:18 UTC
  • Revision ID: me@brandonholtsclaw.com-20120530073118-5yhyjv4yp8bheiil
speed test

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
set -eu
 
4
 
 
5
## no local DB so we're gonna run this at config-changed for now
 
6
 
 
7
 
 
8
juju-log "We've got a db"
 
9
hostname=`unit-get public-address`
 
10
private_name=`hostname -f`
 
11
juju-log "Retrieved hostname: $hostname"
 
12
 
 
13
# Check we haven't already been setup.
 
14
wp_install_path="/var/www/omgubuntu.co.uk"
 
15
config_file_path="$wp_install_path/wp-config.php"
 
16
config_info_path="$wp_install_path/wp-info.php"
 
17
 
 
18
if [ -f "$config_file_path" ]; then
 
19
        juju-log "OMG Ubuntu is already setup, just silently going away"
 
20
        exit 0
 
21
fi
 
22
 
 
23
#database=`relation-get database`
 
24
#user=`relation-get user`
 
25
#password=`relation-get password`
 
26
#host=`relation-get private-address`
 
27
 
 
28
database='omgubuntu';
 
29
user='omgubu';
 
30
password='omgnolove68';
 
31
host='ohso-omgdb.chxmcwfnhnyn.eu-west-1.rds.amazonaws.com';
 
32
 
 
33
if [ -z "$database" ] ; then
 
34
    exit 0
 
35
fi
 
36
 
 
37
S3_BUCKET=`config-get s3-bucket`
 
38
 
 
39
secret_key=`pwgen 10 1`
 
40
secret_key='ileingeiru';
 
41
 
 
42
source "/usr/share/charm-helper/sh/net.sh"
 
43
 
 
44
##
 
45
# OH COME ON WORDPRESS.ORG NO VALID SSL CERTIFICATE?
 
46
# Psh, whatever, plain-text for now. #blamenacin
 
47
# https://twitter.com/#!/marcoceppi/status/181570187655520260
 
48
LATEST_WORDPRESS="http://wordpress.org/latest.tar.gz"
 
49
DOWNLOAD=`ch_get_file "$LATEST_WORDPRESS" "http://wordpress.org/latest.tar.gz.sha1"`
 
50
##
 
51
 
 
52
if [ ! -f "$DOWNLOAD" ] || [ -z "$DOWNLOAD" ]; then
 
53
        juju-log "Failed to retrieve $LATEST_WORDPRESS"
 
54
        exit 1
 
55
fi
 
56
 
 
57
juju-log "Extract ALL THE FILES"
 
58
tar -xzf $DOWNLOAD
 
59
 
 
60
mkdir -p $wp_install_path
 
61
 
 
62
juju-log "Move them in to place, but just 'drop' them in place."
 
63
rsync -az wordpress/ $wp_install_path
 
64
 
 
65
juju-log "Clean up"
 
66
rm -rf wordpress
 
67
 
 
68
juju-log "Dropping OMG specific files: Themes, plugins, etc in to position"
 
69
rsync -az files/wordpress/ $wp_install_path
 
70
 
 
71
juju-log "Writing wordpress config file $config_file_path"
 
72
# Write the wordpress config
 
73
cat > $config_info_path <<EOF
 
74
<?php
 
75
define('DB_NAME', 'omgubuntu');
 
76
define('DB_USER', 'omgubu');
 
77
define('DB_PASSWORD', 'omgnolove68');
 
78
define('DB_HOST', 'ohso-omgdb.chxmcwfnhnyn.eu-west-1.rds.amazonaws.com');
 
79
define('SECRET_KEY', 'ileingeiru');
 
80
 
 
81
define('WP_CACHE', true);
 
82
 
 
83
/*
 
84
define('AUTH_KEY', '$secret_key');
 
85
define('SECURE_AUTH_KEY', '$secret_key');
 
86
define('LOGGED_IN_KEY', '$secret_key');
 
87
define('NONCE_KEY', '$secret_key');
 
88
*/
 
89
 
 
90
\$table_prefix  = 'wp_';
 
91
 
 
92
EOF
 
93
 
 
94
cat > $config_file_path <<EOF
 
95
<?php
 
96
 
 
97
/* That's all, stop editing! Happy blogging. */
 
98
 
 
99
/** Absolute path to the WordPress directory. */
 
100
if ( !defined('ABSPATH') )
 
101
        define('ABSPATH', dirname(__FILE__) . '/');
 
102
 
 
103
/** Pull in the config information */
 
104
require_once(ABSPATH . 'wp-info.php');
 
105
 
 
106
/** Sets up WordPress vars and included files. */
 
107
require_once(ABSPATH . 'wp-settings.php');
 
108
 
 
109
remove_filter('template_redirect', 'redirect_canonical');
 
110
 
 
111
EOF
 
112
chmod 0644 $config_file_path
 
113
 
 
114
juju-log "Enabling apache site: $hostname"
 
115
 
 
116
chown -R www-data.www-data $wp_install_path
 
117
 
 
118
#if [ ! -f /etc/cron.daily/omg-backup ]; then
 
119
#       uju-log "Put the backup process in place"
 
120
#       rsync -az files/omg-backup /etc/cron.daily/
 
121
#       chmod 0755 /etc/cron.daily/omg-backup
 
122
#fi
 
123
 
 
124
#sed -i -e "s@DB_HOST=\".*\"@DB_HOST=\"$host\"@" \
 
125
#    -e "s@DB_USER=\".*\"@DB_USER=\"$user\"@" \
 
126
#    -e "s@DB_PASS=\".*\"@DB_PASS=\"$password\"@" \
 
127
#    -e "s@DB_NAME=\".*\"@DB_NAME=\"$database\"@" \
 
128
#    -e "s@S3_BUCKET=\".*\"@S3_BUCKET=\"$S3_BUCKET\"@" \
 
129
#    /etc/cron.daily/omg-backup
 
130
 
 
131
cat "* * * * * /usr/bin/php -q /var/www/omgubuntu.co.uk/cron/post_flush.php" > /var/spool/cron/crontabs/root
 
132
 
 
133
 
 
134
juju-log "Restarting cron"
 
135
service cron restart
 
136
 
 
137
# Restart apache
 
138
juju-log "Restarting nginx service"
 
139
service nginx restart
 
140
service php5-fpm restart
 
141
 
 
142
# Make it publicly visible, once the wordpress service is exposed
 
143
open-port 80/tcp
 
144
open-port 8080/tcp