Merge lp:~marcoceppi/charms/precise/wordpress/apache-dog-pile into lp:charms/wordpress

Proposed by Marco Ceppi
Status: Merged
Approved by: Mark Mims
Approved revision: 81
Merged at revision: 61
Proposed branch: lp:~marcoceppi/charms/precise/wordpress/apache-dog-pile
Merge into: lp:charms/wordpress
Diff against target: 828 lines (+392/-155)
16 files modified
README.md (+19/-1)
config.yaml (+8/-14)
files/charm/apache/etc_apache2_conf-d_php5-fpm.conf (+6/-0)
files/charm/apache/etc_apache2_sites-enabled_loadbalancer (+21/-0)
files/charm/apache/etc_apache2_sites-enabled_wordpress (+20/-0)
hooks/config-changed (+107/-3)
hooks/db-relation-changed (+9/-19)
hooks/install (+5/-30)
hooks/loadbalancer-relation-changed (+20/-1)
hooks/loadbalancer-relation-joined (+97/-44)
hooks/start (+2/-1)
hooks/stop (+2/-3)
hooks/upgrade-charm (+6/-0)
hooks/website-relation-joined (+3/-1)
inc/common (+66/-37)
revision (+1/-1)
To merge this branch: bzr merge lp:~marcoceppi/charms/precise/wordpress/apache-dog-pile
Reviewer Review Type Date Requested Status
Mark Mims (community) Needs Fixing
Review via email: mp+139307@code.launchpad.net

Description of the change

This is another pretty big merge, so to you who's reviewing - first thank you! Second, sorry. Third, I'm not really.

The primary purpose of this merge is to add Apache2 as a web engine for organizations/people who don't trust nginx yet. This adds the "engine" configuration option with either a value of "nginx" or "apache2". Scale-out peer relation still works. To best test this deploy wp and mysql, enable debug config option, check /_debug/info.php - make sure nginx is the server software, change engine, wait for about 5 mins, check info.php for apache.

Other changes
- Using charm-helper-bash/vcs now, opens up support for hg and svn wp-content, better git/bzr support
- Removed default wp-content config value, it should have been an example, not the default
- Copyright fixes
- Added support for arbitrarily building the files from loadbalancer relation via loadbalancer-rebuild in hooks
- website relation now pushes port 8080 instead, making this charm compatible with other proxy charms if the user wants to not use the peer lb

I'm still testing support for upgrading from current version to this version via upgrade charm and any negative impacts from this. Preliminary research shows that this won't break existing installs.

To post a comment you must log in.
67. By Marco Ceppi

Don't need to listen on 80

68. By Marco Ceppi

Make sure sed expands shell variable

69. By Marco Ceppi

Enable multiverse for the apache2 stuff

70. By Marco Ceppi

Backwards compat fix

71. By Marco Ceppi

Use the restart hook

Revision history for this message
Mark Mims (mark-mims) wrote :

multiple units are failing... tried this two ways: add-unit to existing running stack as well as deploy multiple units up front.

units come up in configure-error

I'll attach logs from one of the units.

review: Needs Fixing
Revision history for this message
Mark Mims (mark-mims) wrote :

> multiple units are failing... tried this two ways: add-unit to existing
> running stack as well as deploy multiple units up front.
>
> units come up in configure-error
>
> I'll attach logs from one of the units.

ok, maybe not... pasting logs: http://paste.ubuntu.com/1426284/

72. By Marco Ceppi

Server lines need a ';' and when loading from cache need to strip() results

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Thanks, not sure how this got overlooked. It's repaired now!

Revision history for this message
Mark Mims (mark-mims) wrote :

nother spin now

Revision history for this message
Mark Mims (mark-mims) wrote :

bit a show-stopper... just a note
------------------8<-----------------------

little bit of a problem with the way loadbalancer is called...

here's the situation:

bootstrap
deploy mysql
deploy wordpress wp -n7
add-relation wp mysql
...time...
juju set engine=apache2

all the instances reconfigure to apache instead of nginx, but the loadbalancer relations aren't called again, so the instances are all just passthrough.

------------------8<-----------------------

Revision history for this message
Mark Mims (mark-mims) wrote :

_not_ a show-stopper... just a note

> ------------------8<-----------------------
>
> little bit of a problem with the way loadbalancer is called...
>
> here's the situation:
>
> bootstrap
> deploy mysql
> deploy wordpress wp -n7
> add-relation wp mysql
> ...time...
> juju set engine=apache2
>
> all the instances reconfigure to apache instead of nginx, but the loadbalancer
> relations aren't called again, so the instances are all just passthrough.
>
>
> ------------------8<-----------------------

73. By Marco Ceppi

Fix to loadbalancer conf name for apache2

74. By Marco Ceppi

Fix to balancermember lines and conditional for nginx only memcached configuration

75. By Marco Ceppi

Enable proxy_balancer

76. By Marco Ceppi

Include proxy_http

77. By Marco Ceppi

proxy_http

78. By Marco Ceppi

Set the request header to make sure assets work properly

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Hi Mark,

Thanks for taking the time to look over this. Setting the engine should work at anytime as there's a loadbalancer-rebuild script which handles configuration changes. I've fixed that script to actually work and several other changes to make Apache2 loadbalanced match what occurs in Nginx. There are still improvements to be made for efficiency of Apache2 but I'll save that for a future MP.

79. By Marco Ceppi

Preserve host

80. By Marco Ceppi

Make sure apache respects the canonical name for cookies and the like

81. By Marco Ceppi

Fix for secrety key and cookies

Revision history for this message
Mark Mims (mark-mims) wrote :

beauty man...

passed all my variations of engine switching with flying colors

thanks for taking the time to work through all this!

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Thank you so much for taking the time to walk through this big merge. New Years resolution: more managable merge proposals!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2012-08-31 15:56:54 +0000
3+++ README.md 2012-12-13 18:15:24 +0000
4@@ -113,6 +113,21 @@
5
6 The debugging is disabled by default.
7
8+## Engine
9+
10+By default the WordPress charm will install nginx and php5-fpm to serve pages. In the event you do not wish to use nginx - for whatever reason - you can switch to Apache2.
11+This will provide a near identical workflow as if you were using nginx with one key difference: memcached. In nginx, the cached pages are served from memcached prior to
12+hitting the php contents, this isn't possible with apache2. As such memcached support still works, since it falls back to the WordPress caching engine, but it's not as robust.
13+Otherwise, Apache2 will still perform balancing and everything else mentioned above. You can switch between engines at will with the following:
14+
15+ juju set wordpress engine=apache2
16+
17+Then back to nginx:
18+
19+ juju set wordpress engine=nginx
20+
21+Any other value will result in the default (nginx) being used.
22+
23 # Caveats
24
25 ## HP Cloud
26@@ -146,7 +161,7 @@
27
28 juju add-unit -n3 wordpress
29
30-## I want more caching, I want MEMCACHING!
31+## I want more caching, I want MEMCACH(ED)ING!
32
33 Why not? We could ALL use more caching. Deploy a memcached server and relate it to your WordPress service to add memcache caching. This will
34 automagically install [WP-FFPC](http://wordpress.org/extend/plugins/wp-ffpc/) (regardless of your tuning settings) and configure it to cache
35@@ -159,6 +174,9 @@
36
37 This setup will also synchronize the flushing of cache across all WordPress nodes, making it ideal to avoid stale caches.
38
39+A small note, when using the Apache2 engine and memcache, all request will still be sent to WordPress via Apache where typical caching
40+procedures will take place and wp-ffpc will render the memcached page.
41+
42 ## I don't want to run three different machines for one WP install
43
44 There is a "hack" that will allow you to deploy multiple full services to the same machine as the bootstrap node, this has nothing to do with
45
46=== modified file 'config.yaml'
47--- config.yaml 2012-08-15 20:58:31 +0000
48+++ config.yaml 2012-12-13 18:15:24 +0000
49@@ -3,24 +3,18 @@
50 type: string
51 default: "single"
52 description: |
53- This is the tuning level for the WordPress setup. There are three options: "bare", "single", and "optimized".
54- "bare" will give you a nearly un-altered WordPress setup, as if you'd downloaded and set it up yourself.
55- "single" will provide you with everything you need to run a singlular unit of WordPress. This doesn't take in to
56- consideration that you'll be scaling at all. However, it will allow you to use WordPress free of any troubles and pesky
57- limitations that typically happen during "optimized". While you _can_ scale out with this setting I encourage you read the README
58- "optimized" will give you a hardened WordPress setup. Some of the features in the Admin panel will be locked down and theme edits/plugins
59- can only be updated through he charm. This is the recommended setup for those who are in serious need of constant scaling.
60+ This is the tuning level for the WordPress setup. There are three options: "bare", "single", and "optimized". "bare" will give you a nearly un-altered WordPress setup, as if you'd downloaded and set it up yourself. "single" will provide you with everything you need to run a singlular unit of WordPress. This doesn't take in to consideration that you'll be scaling at all. However, it will allow you to use WordPress free of any troubles and pesky limitations that typically happen during "optimized". While you _can_ scale out with this setting I encourage you read the README "optimized" will give you a hardened WordPress setup. Some of the features in the Admin panel will be locked down and theme edits/plugins can only be updated through he charm. This is the recommended setup for those who are in serious need of constant scaling.
61 wp-content:
62 type: string
63- default: "https://github.com/jujutools/wordpress-site.git"
64+ default: ""
65 description: |
66- This is a full repository path to where the WordPress wp-contents can be found. At this time both Git and Bzr are
67- supported. An example of what a wp-content repository should look like can be found at http://github.com/jujutools/wordpress-site.
68+ This is a full repository path to where the WordPress wp-contents can be found. At this time Git, BZR, SVN, and HG are supported. An example of what a wp-content repository should look like can be found at http://github.com/jujutools/wordpress-site.
69 debug:
70 type: string
71 default: "no"
72 description: |
73- Setting this option to "yes" will expose /_debug on all instances over HTTP. In the _debug folder are two scripts, info.php and apc.php.
74- info.php will display the phpinfo information for that server while the apc.php will provide APC cache stats (as well as additional administrative
75- options for APC).
76-
77+ Setting this option to "yes" will expose /_debug on all instances over HTTP. In the _debug folder are two scripts, info.php and apc.php. info.php will display the phpinfo information for that server while the apc.php will provide APC cache stats (as well as additional administrative options for APC).
78+ engine:
79+ type: string
80+ default: nginx
81+ description: "Currently two web server engines are supported: nginx and apache. For the majority of deployments nginx will be the prefered choice. See the Readme for more details"
82
83=== added directory 'files/charm/apache'
84=== added file 'files/charm/apache/etc_apache2_conf-d_php5-fpm.conf'
85--- files/charm/apache/etc_apache2_conf-d_php5-fpm.conf 1970-01-01 00:00:00 +0000
86+++ files/charm/apache/etc_apache2_conf-d_php5-fpm.conf 2012-12-13 18:15:24 +0000
87@@ -0,0 +1,6 @@
88+<IfModule mod_fastcgi.c>
89+ AddHandler php5-fcgi .php
90+ Action php5-fcgi /php5-fcgi
91+ Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
92+ FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
93+</IfModule>
94
95=== added file 'files/charm/apache/etc_apache2_sites-enabled_loadbalancer'
96--- files/charm/apache/etc_apache2_sites-enabled_loadbalancer 1970-01-01 00:00:00 +0000
97+++ files/charm/apache/etc_apache2_sites-enabled_loadbalancer 2012-12-13 18:15:24 +0000
98@@ -0,0 +1,21 @@
99+## This is the standard apache configuration file, only serving over 80.
100+## This will be re-written when loadbalancer-relation is run, creating
101+## the proxy balancer setups, etc. Untill then there's not need to proxypass
102+## to another apache virtual host
103+
104+<VirtualHost *:80>
105+ ServerName localhost
106+ ServerAlias *
107+ ServerAdmin webmaster@localhost
108+
109+ DocumentRoot /var/www
110+ <Directory /var/www>
111+ Options Indexes FollowSymLinks MultiViews
112+ AllowOverride All
113+ </Directory>
114+
115+ ErrorLog ${APACHE_LOG_DIR}/wordpress-error.log
116+
117+ LogLevel warn
118+ CustomLog ${APACHE_LOG_DIR}/wordpress-access.log combined
119+</VirtualHost>
120
121=== added file 'files/charm/apache/etc_apache2_sites-enabled_wordpress'
122--- files/charm/apache/etc_apache2_sites-enabled_wordpress 1970-01-01 00:00:00 +0000
123+++ files/charm/apache/etc_apache2_sites-enabled_wordpress 2012-12-13 18:15:24 +0000
124@@ -0,0 +1,20 @@
125+Listen *:8080
126+
127+<VirtualHost *:8080>
128+ ServerName localhost
129+ ServerAlias *
130+ ServerAdmin webmaster@localhost
131+
132+ UseCanonicalName Off
133+
134+ DocumentRoot /var/www
135+ <Directory /var/www>
136+ Options Indexes FollowSymLinks MultiViews
137+ AllowOverride All
138+ </Directory>
139+
140+ ErrorLog ${APACHE_LOG_DIR}/wordpress-error.log
141+
142+ LogLevel warn
143+ CustomLog ${APACHE_LOG_DIR}/wordpress-access.log combined
144+</VirtualHost>
145
146=== modified file 'hooks/config-changed'
147--- hooks/config-changed 2012-08-24 20:59:04 +0000
148+++ hooks/config-changed 2012-12-13 18:15:24 +0000
149@@ -4,13 +4,117 @@
150
151 source inc/common
152
153+##
154+# This is where things can get a bit hectic. So this long blog is just to
155+# help preface what's going on here. When this hook fires it will always
156+# try to re-configure the entire unit. It's like a GOD hook, triggering
157+# or using data from every other hook with the exception of the install
158+# and upgrade-charm hooks.
159+#
160+# First, get a bunch of configuration values. The idea being this is should
161+# be the only place that config-get is run as it's "unreliable" anywhere else
162+# Data should then either be passed to functions or written down - you know
163+# "YOU SHOULD ALWAYS LEAVE A NOTE!"
164+#
165+# From here, the web engine will either be updated or left alone. We always
166+# assume it's going to be nginx unless you specify apache. So if you put
167+# "lighttpd" or "i love apache" you're going to get nginx, so don't do that.
168+# Configuration files are re-written every time. This is to make sure that
169+# any changes to long running units overtime are included. It may seem
170+# expensive to keep re-writing the same files but in the end having all
171+# the units in a sane and identical state is worth it.
172+#
173+# Next, we do some small file moving around. Just for debug stuff.
174+#
175+# After that tuning levels are decided and executed. This is a bit more
176+# involved than just running a function, check inc/common for that craziness
177+#
178+# After that, it's time to get any user-defined content! do_vcs does that
179+# and a little more
180+#
181+# Caching stuff, basically "DO WE HAVE MEMCACHED, GOOD LETS DO CONFIG"
182+#
183+# Then we stop and start everything again and wait for the next round.
184+##
185+
186 tuning_level=`config-get tuning`
187+wp_content_repo=`config-get wp-content`
188+expose_info=`config-get debug`
189+engine=`config-get engine`
190+unit_address=`unit-get private-address`
191+
192 # Make it lower case
193 tuning_level=${tuning_level,,}
194-
195-wp_content_repo=`config-get wp-content`
196-expose_info=`config-get debug`
197 expose_info=${expose_info,,}
198+engine=${engine,,}
199+
200+
201+if [ "$engine" == "apache" ] || [ "$engine" == "apache2" ]; then
202+ if [ -f .web-engine ]; then
203+ web_engine=`cat .web-engine`
204+ service $web_engine stop
205+ fi
206+ sed -i -e "s/# deb \(.*\) multiverse/deb \1 multiverse/g" /etc/apt/sources.list #for libapache2-mod-fastcgi
207+ apt-get update
208+ apt-get -y purge nginx
209+ apt-get install -y apache2-mpm-worker libapache2-mod-fastcgi
210+ service apache2 stop
211+
212+ rm -f /var/www/index.html
213+
214+ rm -f /etc/apache2/sites-enabled/*
215+ a2enmod actions fastcgi alias proxy_balancer proxy_http headers
216+
217+ install -o root -g root -m 0644 files/charm/apache/etc_apache2_conf-d_php5-fpm.conf /etc/apache2/conf.d/php5-fpm.conf
218+
219+ juju-log "Installing Apache loadbal config..."
220+ install -o root -g root -m 0644 files/charm/apache/etc_apache2_sites-enabled_loadbalancer /etc/apache2/sites-available/loadbalancer
221+ sed -i -e "s/^ ServerName .*/ ServerName ${unit_address}/" /etc/apache2/sites-available/loadbalancer
222+ a2ensite loadbalancer
223+
224+ juju-log "Installing Apache wordpress config..."
225+ install -o root -g root -m 0644 files/charm/apache/etc_apache2_sites-enabled_wordpress /etc/apache2/sites-available/wordpress
226+ a2ensite wordpress
227+
228+ echo "apache2" > .web-engine
229+else
230+ if [ -f .web-engine ]; then
231+ web_engine=`cat .web-engine`
232+ service $web_engine stop
233+ fi
234+ apt-get -y purge apache2* libapache2*
235+ apt-get install -y nginx
236+ service nginx stop
237+
238+ juju-log "Cleaning any old or default nginx site configs ..."
239+ rm -f /etc/nginx/sites-enabled/*
240+ rm -f /etc/nginx/conf.d/*
241+
242+ juju-log "Installing nginx common config ..."
243+ rm -f /etc/nginx/nginx.conf
244+ install -o root -g root -m 0644 files/charm/nginx/etc_nginx_nginx.conf /etc/nginx/nginx.conf
245+
246+ juju-log "Installing nginx actual site config ..."
247+ #rm -f /etc/nginx/sites-available/
248+ install -o root -g root -m 0644 files/charm/nginx/etc_nginx_sites-enabled_wordpress /etc/nginx/sites-available/wordpress
249+ ln -sf ../sites-available/wordpress /etc/nginx/sites-enabled/wordpress
250+
251+ juju-log "Installing nginx loadbal config ..."
252+ rm -f /etc/nginx/sites-available/loadbalancer
253+ install -o root -g root -m 0644 files/charm/nginx/etc_nginx_sites-enabled_loadbalancer /etc/nginx/sites-available/loadbalancer
254+ ln -sf ../sites-available/loadbalancer /etc/nginx/sites-enabled/loadbalancer
255+
256+ juju-log "Moving nginx var dirs to /mnt storage ..."
257+ rsync -az /var/lib/nginx /mnt/ && rm -rf /var/lib/nginx && ln -s /mnt/nginx /var/lib/
258+
259+ echo "nginx" > .web-engine
260+fi
261+
262+# http://i.imgur.com/TUF91.gif
263+hooks/loadbalancer-rebuild
264+
265+juju-log "Restarting Services ..."
266+source hooks/restart
267
268 if [ ! -f $config_file_path ]; then
269 juju-log "Nothing to configure, since nothing is installed"
270
271=== modified file 'hooks/db-relation-changed'
272--- hooks/db-relation-changed 2012-09-25 13:58:24 +0000
273+++ hooks/db-relation-changed 2012-12-13 18:15:24 +0000
274@@ -18,29 +18,20 @@
275 host=`relation-get private-address`
276
277 if [ -z "$database" ] ; then
278- exit 0
279+ exit 0
280 fi
281
282-secret_key=`cat .wp-secret`
283-
284 source "/usr/share/charm-helper/sh/net.sh"
285
286-##
287-# OH COME ON WORDPRESS.ORG NO VALID SSL CERTIFICATE?
288-# Psh, whatever, plain-text for now. #blamenacin
289-# https://twitter.com/#!/marcoceppi/status/181570187655520260
290-# I was wrong, we need to use something other than WGET, like cURL
291-LATEST_WORDPRESS="https://wordpress.org/latest.tar.gz"
292-DOWNLOAD=`ch_get_file "$LATEST_WORDPRESS" "https://wordpress.org/latest.tar.gz.sha1"`
293-##
294+payload=`ch_get_file "https://wordpress.org/latest.tar.gz" "https://wordpress.org/latest.tar.gz.sha1"`
295
296-if [ ! -f "$DOWNLOAD" ] || [ -z "$DOWNLOAD" ]; then
297- juju-log "Failed to retrieve $LATEST_WORDPRESS"
298+if [ ! -f "$payload" ] || [ -z "$payload" ]; then
299+ juju-log "Failed to retrieve latest.tar.gz"
300 exit 1
301 fi
302
303-juju-log "Extract ALL THE FILES"
304-tar -xzf $DOWNLOAD
305+juju-log "Extract ALL THE FILES!"
306+tar -xzf $payload
307
308 mkdir -p $wp_install_path
309
310@@ -50,6 +41,8 @@
311 juju-log "Clean up"
312 rm -rf wordpress
313
314+secret_key=`cat .wp-secret`
315+
316 juju-log "Writing wordpress config file $config_file_path"
317 # Write the wordpress config
318 cat > $config_info_path <<EOF
319@@ -101,10 +94,7 @@
320 chown -R www-data.www-data $wp_install_path
321
322 . hooks/config-changed
323-
324-# Restart nginx
325-juju-log "Restarting nginx service"
326-service nginx restart
327+. hooks/restart
328
329 # Make it publicly visible, once the wordpress service is exposed
330 open-port 80/tcp
331
332=== modified file 'hooks/install'
333--- hooks/install 2012-09-26 23:30:54 +0000
334+++ hooks/install 2012-12-13 18:15:24 +0000
335@@ -3,15 +3,12 @@
336 add-apt-repository ppa:charmers/charm-helpers
337 apt-get update && apt-get -y upgrade
338
339-apt-get -y install php5-memcache mysql-client pwgen nginx php5 php5-fpm \
340+apt-get -y install php5-memcache mysql-client pwgen php5 php5-fpm \
341 php-apc mailutils php-mail sysstat php5-mysql php5-mcrypt php5-memcache \
342- charm-helper-sh php5-curl rsync nfs-common bzr git-core mktemp
343+ charm-helper-sh php5-curl rsync nfs-common git-core mktemp
344
345 modprobe nfs
346
347-juju-log "Removing PHP Default Cron ..."
348-rm -f /etc/cron.d/php5
349-
350 juju-log "Making /mnt/tmp dir ..."
351 mkdir -p /mnt/tmp
352 chmod 1777 /mnt/tmp
353@@ -27,37 +24,15 @@
354 mkdir -p /mnt/ramdisk/phpfpm-cache
355 chmod -R 1777 /mnt/ramdisk
356
357-juju-log "Cleaning any old or default nginx site configs ..."
358-rm -f /etc/nginx/sites-enabled/*
359-rm -f /etc/nginx/conf.d/*
360-
361-juju-log "Installing Nginx common config ..."
362-rm -f /etc/nginx/nginx.conf
363-install -o root -g root -m 0644 files/charm/nginx/etc_nginx_nginx.conf /etc/nginx/nginx.conf
364-
365-juju-log "Installing Nginx actual site config ..."
366-#rm -f /etc/nginx/sites-available/
367-install -o root -g root -m 0644 files/charm/nginx/etc_nginx_sites-enabled_wordpress /etc/nginx/sites-available/wordpress
368-ln -sf ../sites-available/wordpress /etc/nginx/sites-enabled/wordpress
369-
370-juju-log "Installing Nginx loadbal config ..."
371-rm -f /etc/nginx/sites-available/loadbalancer
372-install -o root -g root -m 0644 files/charm/nginx/etc_nginx_sites-enabled_loadbalancer /etc/nginx/sites-available/loadbalancer
373-ln -sf ../sites-available/loadbalancer /etc/nginx/sites-enabled/loadbalancer
374-
375 juju-log "Installing PHP-FPM pool configs ..."
376 rm -f /etc/php5/fpm/pool.d/*
377 install -o root -g root -m 0644 files/charm/php/php5-fpm_pool.d_www.conf /etc/php5/fpm/pool.d/www.conf
378-
379-juju-log "Moving PHP and Nginx var dirs to /mnt storage ..."
380-rsync -az /var/lib/nginx /mnt/ && rm -rf /var/lib/nginx && ln -s /mnt/nginx /var/lib/
381 rsync -az /var/lib/php5 /mnt/ && rm -rf /var/lib/php5 && ln -s /mnt/php5 /var/lib/
382
383-juju-log "Restarting Services ..."
384-source hooks/restart
385-
386 juju-log "Creating random secret key ..."
387-pwgen -s 10 1 > .wp-secret
388+if [ ! -f .wp-secret ]; then
389+ pwgen -s 10 1 > .wp-secret
390+fi
391
392 juju-log "Installing wp-cli to make this charm's life a little easier ..."
393 save_pwd=`pwd`
394
395=== added symlink 'hooks/loadbalancer-rebuild'
396=== target is u'loadbalancer-relation-joined'
397=== modified file 'hooks/loadbalancer-relation-changed'
398--- hooks/loadbalancer-relation-changed 2012-08-29 20:57:32 +0000
399+++ hooks/loadbalancer-relation-changed 2012-12-13 18:15:24 +0000
400@@ -1,4 +1,23 @@
401 #!/bin/bash
402+#
403+# loadbalancer-relation-changed - hook for when loadbalancer peer relation changes
404+#
405+# Copyright (C) 2012 Marco Ceppi
406+# Author: Marco Ceppi <marco@ceppi.net>
407+#
408+# This program is free software: you can redistribute it and/or modify
409+# it under the terms of the GNU General Public License as published by
410+# the Free Software Foundation, either version 3 of the License, or
411+# (at your option) any later version.
412+#
413+# This program is distributed in the hope that it will be useful,
414+# but WITHOUT ANY WARRANTY; without even the implied warranty of
415+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
416+# GNU General Public License for more details.
417+#
418+# You should have received a copy of the GNU General Public License
419+# along with this program. If not, see <http://www.gnu.org/licenses/>.
420+#
421
422 source inc/common
423
424@@ -14,5 +33,5 @@
425
426 if [ -f "$config_info_path" ]; then
427 secret_key=`cat .wp-secret`
428- sed -i -e "s/define\('SECRET_KEY',.*\);/define\('SECRET_KEY', '$secret_key'\)\;/" $config_info_path
429+ sed -i -e "s/define('SECRET_KEY',.*/define('SECRET_KEY', '$secret_key')\;/" $config_info_path
430 fi
431
432=== modified file 'hooks/loadbalancer-relation-joined'
433--- hooks/loadbalancer-relation-joined 2012-08-29 20:57:32 +0000
434+++ hooks/loadbalancer-relation-joined 2012-12-13 18:15:24 +0000
435@@ -1,6 +1,6 @@
436 #!/usr/bin/env python
437 #
438-# reverseproxy-relation-changed - hook for when reverse proxy relation changes
439+# reverseproxy-relation-changed - hook for when proxy relation changes
440 #
441 # Copyright (C) 2011 Canonical Ltd.
442 # Author: Clint Byrum <clint.byrum@canonical.com>
443@@ -22,21 +22,64 @@
444 import sys
445 import os
446 import subprocess
447-import json
448 import tempfile
449-import glob
450-
451-from socket import getaddrinfo
452-
453-remote_unit = os.environ.get("JUJU_REMOTE_UNIT")
454-
455-service_name, _ = remote_unit.split("/")
456-
457-t1 = """# Generated by juju
458+
459+rebuild = os.path.basename(sys.argv[0]) == 'loadbalancer-rebuild'
460+
461+pa = subprocess.Popen(["unit-get", "private-address"], stdout=subprocess.PIPE,
462+ close_fds=True)
463+unit_address = pa.stdout.read().strip()
464+
465+try:
466+ with open('.web-engine','r') as f:
467+ engine = f.readline().strip()
468+except IOError:
469+ engine = 'nginx'
470+
471+if engine == 'apache2':
472+ conf_name = "loadbalancer"
473+ servers = """
474+<Proxy balancer://backend>
475+ BalancerMember http://127.0.0.1:8080/
476+"""
477+ server_line = " BalancerMember http://%s:8080/\n"
478+ server_end = """
479+ ProxySet lbmethod=bybusyness
480+</Proxy>
481+"""
482+ t1 = '# Generated by juju'
483+ template = """
484+<VirtualHost *:80>
485+
486+"""
487+ template += " ServerName %s\n" % unit_address
488+ template += """
489+ ServerAlias *
490+ LogLevel warn
491+ ErrorLog ${APACHE_LOG_DIR}/wordpress-balancer-error.log
492+ ProxyPreserveHost On
493+ <Location />
494+ Order allow,deny
495+ Allow from all
496+ ProxyPass balancer://backend/
497+ ProxyPassReverse balancer://backend/
498+ </Location>
499+</VirtualHost>
500+"""
501+else:
502+ conf_name = "loadbalancer"
503+ servers = """
504+upstream backend {
505+ server 127.0.0.1:8080;
506+"""
507+ server_line = " server %s:8080;\n"
508+ server_end = '}'
509+
510+ t1 = """# Generated by juju
511 proxy_cache_path /mnt/ramdisk/proxy-cache levels=1:2 keys_zone=proxycache:5m max_size=1000m;
512 """
513-# servers will go here
514-template = """
515+ # servers will go here
516+ template = """
517 server {
518 listen 80 default;
519 server_name _;
520@@ -77,44 +120,54 @@
521 }
522 """
523
524-units = []
525-p = subprocess.Popen("relation-list", stdout=subprocess.PIPE)
526-for unit in p.stdout:
527- units.append(unit.strip())
528-
529-print units
530-
531-servers = """
532-upstream backend {
533- server 127.0.0.1:8080;
534-"""
535-for unit in units:
536- p = subprocess.Popen(["relation-get", "private-address", unit],
537- stdout=subprocess.PIPE, close_fds=True)
538- paddress = p.stdout.read().strip()
539- p.wait()
540- # Add all configured units:
541- servers += (" server %s:8080;\n" % (paddress))
542-servers += '}'
543+if rebuild:
544+ try:
545+ with open('.loadbalancer-units') as units:
546+ for paddress in units:
547+ servers += (server_line % (paddress.strip()))
548+ except IOError:
549+ pass
550+else:
551+ units = []
552+ p = subprocess.Popen("relation-list", stdout=subprocess.PIPE)
553+ for unit in p.stdout:
554+ units.append(unit.strip())
555+
556+ print units
557+
558+ lb_file = open('.loadbalancer-units', 'w')
559+ for unit in units:
560+ p = subprocess.Popen(["relation-get", "private-address", unit],
561+ stdout=subprocess.PIPE, close_fds=True)
562+ paddress = p.stdout.read().strip()
563+ p.wait()
564+ lb_file.write("%s\n" % paddress)
565+ # Add all configured units:
566+ servers += (server_line % (paddress))
567+
568+ lb_file.close()
569+servers += server_end
570
571 print servers
572
573-with tempfile.NamedTemporaryFile(dir="/etc/nginx/sites-available/",prefix="loadbalancer", delete=False) as conf:
574+with tempfile.NamedTemporaryFile(dir="/etc/%s/sites-available/" % engine,
575+ prefix='lb', delete=False) as conf:
576 conf.write(t1 + servers + template)
577 try:
578- os.unlink("/etc/nginx/sites-available/loadbalancer.old")
579- except:
580- pass
581- try:
582- os.rename("/etc/nginx/sites-available/loadbalancer","/etc/nginx/sites-available/loadbalancer.old")
583- except:
584- pass
585- try:
586- os.rename(conf.name, "/etc/nginx/sites-available/loadbalancer")
587+ os.unlink("/etc/%s/sites-available/%s.old" % (engine, conf_name))
588+ except:
589+ pass
590+ try:
591+ os.rename("/etc/%s/sites-available/%s" % (engine, conf_name),
592+ "/etc/%s/sites-available/%s.old" % (engine, conf_name))
593+ except:
594+ pass
595+ try:
596+ os.rename(conf.name, "/etc/%s/sites-available/%s" % (engine, conf_name))
597 except:
598 os.unlink(conf.name)
599
600-subprocess.call(["service", "nginx", "start"])
601-subprocess.check_call(["service", "nginx", "reload"])
602+subprocess.call(["service", engine, "start"])
603+subprocess.check_call(["service", engine, "reload"])
604
605 subprocess.check_call(["open-port", "80"])
606
607=== modified file 'hooks/start'
608--- hooks/start 2012-04-10 22:26:11 +0000
609+++ hooks/start 2012-12-13 18:15:24 +0000
610@@ -1,4 +1,5 @@
611 #!/bin/bash
612
613+engine=`cat .web-engine`
614 service php5-fpm restart
615-service nginx restart
616+service $engine restart
617
618=== modified file 'hooks/stop'
619--- hooks/stop 2012-08-15 20:09:06 +0000
620+++ hooks/stop 2012-12-13 18:15:24 +0000
621@@ -1,6 +1,5 @@
622 #!/bin/bash
623
624+engine=`cat .web-engine`
625 service php5-fpm stop
626-service nginx stop
627-
628-
629+service $engine stop
630
631=== modified file 'hooks/upgrade-charm'
632--- hooks/upgrade-charm 2012-08-29 20:57:32 +0000
633+++ hooks/upgrade-charm 2012-12-13 18:15:24 +0000
634@@ -12,6 +12,12 @@
635
636 juju-log "Upgrading WordPress core..."
637 wp core update --path=$wp_install_path
638+
639+ # Patch to fix old installations that didn't cookie properly
640+ if [ -f "$wp_install_path/wp-info.php" ] && [ -f .wp-secret ]; then
641+ secret_key=`cat .wp-secret`
642+ sed -i -e "s/define('SECRET_KEY',.*/define('SECRET_KEY', '$secret_key')\;/" $wp_install_path/wp-info.php
643+ fi
644 fi
645
646 hooks/restart
647
648=== modified file 'hooks/website-relation-joined'
649--- hooks/website-relation-joined 2012-08-24 01:14:11 +0000
650+++ hooks/website-relation-joined 2012-12-13 18:15:24 +0000
651@@ -1,2 +1,4 @@
652 #!/bin/sh
653-relation-set port=80 hostname=`unit-get private-address`
654+
655+# Bypass the loadbalancer for $engine and instead just hit the unit
656+relation-set port=8080 hostname=`unit-get private-address`
657
658=== modified file 'inc/common'
659--- inc/common 2012-08-29 20:57:32 +0000
660+++ inc/common 2012-12-13 18:15:24 +0000
661@@ -1,5 +1,23 @@
662 #!/bin/bash
663-
664+#
665+# common - Common functions
666+#
667+# Copyright (C) 2012 Marco Ceppi
668+# Author: Marco Ceppi <marco@ceppi.net>
669+#
670+# This program is free software: you can redistribute it and/or modify
671+# it under the terms of the GNU General Public License as published by
672+# the Free Software Foundation, either version 3 of the License, or
673+# (at your option) any later version.
674+#
675+# This program is distributed in the hope that it will be useful,
676+# but WITHOUT ANY WARRANTY; without even the implied warranty of
677+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
678+# GNU General Public License for more details.
679+#
680+# You should have received a copy of the GNU General Public License
681+# along with this program. If not, see <http://www.gnu.org/licenses/>.
682+#
683
684 hostname=`unit-get public-address`
685 private_name=`hostname -f`
686@@ -12,9 +30,14 @@
687 ####
688 ## The only hook who should ever remove the NFS mount is the nfs-relation-(departed|broken) hook
689 ## Everyone else should just assume it's there or try to mount it. We don't want to loose people's
690-## data, they get mad when that happens
691+## data, they get mad when that happens :(
692 ####
693
694+engine()
695+{
696+ echo `cat .web-engine`
697+}
698+
699 make_bare()
700 {
701 # Un-do APC
702@@ -37,8 +60,13 @@
703 juju-log "Installing PHP apc.ini ..."
704 rm -f /etc/php5/conf.d/apc.ini
705 install -o root -g root -m 0644 files/charm/php/php5_conf.d_apc.ini /etc/php5/conf.d/apc.ini
706+
707+ ## We do NFS here, because Configuration changes cascade. So to get to Optimzied you *must* first
708+ ## make "single" (and by association, "bare"). Since nfs is both a single and optimized thing we do it now.
709+
710 do_nfs
711- juju-log "We are now single"
712+
713+ juju-log "We are now single, ALL THE SINGLE UNITS ALL THE SINGLE UNITS"
714 }
715
716 make_optimized()
717@@ -48,7 +76,7 @@
718 <?php
719 define('DISALLOW_FILE_MODS', TRUE);
720 EOF
721- juju-log "We are now optimized"
722+ juju-log "We are now optimized prime"
723 }
724
725 do_nfs()
726@@ -80,7 +108,9 @@
727
728 do_vcs()
729 {
730- local NEW_REPO_URL="$1"
731+ source "/usr/share/charm-helper/bash/vcs.bash"
732+
733+ local NEW_REPO_URL=${1:-""}
734
735 if [ -z "$NEW_REPO_URL" ]; then
736 rm -f .wp-repo
737@@ -95,47 +125,42 @@
738
739 if [ "$NEW_REPO_URL" != "$REPO_URL" ]; then
740 # We need to determine what kind of URL this is
741- if [ $(echo "$NEW_REPO_URL" | egrep -Ec "^(lp:\~|bzr:\/\/|bzr+ssh:\/\/)") -eq 1 ]; then
742- local repo_type="bzr"
743- local cmd="branch"
744- elif [ $(echo "$NEW_REPO_URL" | egrep -Ec "(^git@|^git:\/\/|\.git$)") -gt 0 ]; then
745- local repo_type="git"
746- local cmd="clone"
747- else
748+
749+ repo_path=`ch_fetch_repo $NEW_REPO_URL`
750+ if [ $? -ne 0 ]; then
751+ juju-log "Failed to fetch repo, charm-helper/bash/vcs.bash exited with $?"
752 return 1
753 fi
754
755- repo_path=$(mktemp -d)
756- $repo_type $cmd $NEW_REPO_URL $repo_path
757 # Write all our new data to disk
758 cat > .wp-repo <<EOF
759 #!/bin/bash
760-REPO_TYPE=$repo_type
761 REPO_URL=$NEW_REPO_URL
762 REPO_PATH=$repo_path
763-REPO_CMD=$cmd
764-
765 EOF
766 source .wp-repo # Just so the rest of this can run all willy nilly
767- fi
768-
769- if [ ! -d "$REPO_PATH" ]; then
770- mkdir -p "$REPO_PATH"
771- $REPO_TYPE $REPO_CMD $REPO_URL $REPO_PATH
772- fi
773-
774- local cwd=`pwd`
775- cd $REPO_PATH
776- $REPO_TYPE pull
777- cd $cwd
778-
779- # This will clean up anything deleted from wp-content specifically
780- rsync -az --delete $REPO_PATH/wp-content/ $wp_install_path/wp-content/
781- # This is just incase people have modifications outside of the wp-content directory
782- rsync -az $REPO_PATH/ $wp_install_path/
783-
784- # This should be an --exclude flag in the RSYNC command, but I'm not quite sure how to make that work properly.
785- rm -rf $wp_install_path/.$REPO_TYPE
786+ else
787+ # Lets just try and do a fetch
788+ ch_update_repo "$REPO_PATH"
789+ if [ $? -ne 0 ]; then
790+ juju-log "Failed to update repository, charm-helper/bash/vcs.bash exited with $?"
791+ return 2
792+ fi
793+ fi
794+
795+ repo_type=`ch_detect_vcs $REPO_PATH`
796+
797+ if [ ! -d "$REPO_PATH/wp-content" ]; then
798+ # This is just someone who has their source control at the root level of the repo.
799+ wp_content_path="$REPO_PATH/wp-content"
800+ rsync -az --delete --exclude ".$repo_type/*" $REPO_PATH/ $wp_install_path/wp-content/
801+ else
802+ # This is a repo with a wp-content folder. So we'll move that then everything else they have in that repo
803+ # to the web root. OMG requirement.
804+ rsync -az --delete --exclude ".$repo_type/*" $REPO_PATH/wp-content/ $wp_install_path/wp-content/
805+ # This is just incase people have modifications outside of the wp-content directory
806+ rsync -az --exclude ".$repo_type/*" $REPO_PATH/ $wp_install_path/
807+ fi
808 }
809
810 do_cache()
811@@ -159,5 +184,9 @@
812 sed -i -e "s/\$wp_ffpc_config\['host'\]=.*/\$wp_ffpc_config\['host'\]='$CACHE_HOST';/" \
813 -e "s/\$wp_ffpc_config\['port'\]=.*/\$wp_ffpc_config\['host'\]='$CACHE_PORT';/" \
814 $wp_install_path/wp-content/advanced-cache.php
815- sed -i -e "s/memcached_pass .*/memcached_pass $CACHE_HOST\:$CACHE_PORT;/" /etc/nginx/sites-enabled/wordpress
816+
817+ engine=`cat .web-engine`
818+ if [ "$engine" == "nginx" ]; then
819+ sed -i -e "s/memcached_pass .*/memcached_pass $CACHE_HOST\:$CACHE_PORT;/" /etc/nginx/sites-enabled/wordpress
820+ fi
821 }
822
823=== modified file 'revision'
824--- revision 2012-08-29 20:57:32 +0000
825+++ revision 2012-12-13 18:15:24 +0000
826@@ -1,1 +1,1 @@
827-83
828+93

Subscribers

People subscribed via source and target branches

to all changes: