Merge lp:~ev/charms/precise/daisy/prodstack-prep into lp:~daisy-pluckers/charms/precise/daisy/trunk

Proposed by Evan
Status: Merged
Merged at revision: 24
Proposed branch: lp:~ev/charms/precise/daisy/prodstack-prep
Merge into: lp:~daisy-pluckers/charms/precise/daisy/trunk
Diff against target: 480 lines (+293/-65)
10 files modified
config.yaml (+81/-4)
hooks/amqp (+2/-18)
hooks/cassandra (+56/-0)
hooks/common (+45/-6)
hooks/config-changed (+27/-3)
hooks/daisy-relation-changed (+7/-0)
hooks/install (+42/-30)
hooks/wsgi-file-relation-changed (+22/-0)
metadata.yaml (+10/-3)
revision (+1/-1)
To merge this branch: bzr merge lp:~ev/charms/precise/daisy/prodstack-prep
Reviewer Review Type Date Requested Status
Daisy Pluckers Pending
Review via email: mp+150110@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2012-11-13 14:23:41 +0000
3+++ config.yaml 2013-02-22 17:25:28 +0000
4@@ -1,4 +1,32 @@
5 options:
6+ basedir:
7+ default: "daisy.ubuntu.com"
8+ type: string
9+ description: Base directory for code
10+ instance_type:
11+ default: "production"
12+ type: string
13+ description: Instance type
14+ user_code_runner:
15+ default: "whoopsie"
16+ type: string
17+ description: The user that runs the code
18+ group_code_runner:
19+ default: "whoopsie"
20+ type: string
21+ description: The group that runs the code
22+ user_code_owner:
23+ default: "webops_deploy"
24+ type: string
25+ description: The user that owns the code
26+ group_code_owner:
27+ default: "webops_deploy"
28+ type: string
29+ description: The group that owns the code
30+ listen_port:
31+ default: 8080
32+ type: int
33+ description: Port for the application to listen on
34 amqp-user:
35 type: string
36 default: 'daisy'
37@@ -15,11 +43,60 @@
38 type: string
39 default: ''
40 description: The AWS access key (EC2_ACCESS_KEY).
41- daisy-ec2-host:
42+ daisy-s3-host:
43 type: string
44 default: ''
45- description: The EC2 IP address.
46- daisy-ec2-bucket:
47+ description: The S3 IP address.
48+ daisy-s3-bucket:
49 type: string
50 default: 'daisy_core_files'
51- description: The EC2 bucket.
52+ description: The S3 bucket.
53+ daisy-openstack-auth-url:
54+ type: string
55+ default: ''
56+ description: |
57+ The OpenStack authentication URL, e.g.:
58+ https://keystone.yourdomain.com:443/v2.0/
59+ daisy-openstack-username:
60+ type: string
61+ default: ''
62+ description: The OpenStack username to authenticate with.
63+ daisy-openstack-password:
64+ type: string
65+ default: ''
66+ description: The OpenStack password to authenticate with.
67+ daisy-openstack-tenant:
68+ type: string
69+ default: ''
70+ description: |
71+ The OpenStack tenant to use, e.g.: yourname_project.
72+ daisy-openstack-region:
73+ type: string
74+ default: ''
75+ description: The OpenStack region to use.
76+ daisy-swift-bucket:
77+ type: string
78+ default: ''
79+ description: |
80+ The OpenStack Swift bucket to use, e.g.: daisy_core_files.
81+ Setting this will use Swift instead of S3 for storing core files.
82+ daisy-cassandra-host:
83+ type: string
84+ default: ''
85+ description: |
86+ Override relations to Cassandra with a specific host address. This
87+ is a temporary measure until cross-environment relations are ready.
88+ daisy-cassandra-username:
89+ type: string
90+ default: ''
91+ description: |
92+ The Cassandra RPC username. Leave blank if one is not needed.
93+ daisy-cassandra-password:
94+ type: string
95+ default: ''
96+ description: |
97+ The Cassandra RPC password. Leave blank if one is not needed.
98+ repository:
99+ type: string
100+ default: 'ppa:daisy-pluckers/prodstack-prep'
101+ description: The location for the daisy-dependencies package.
102
103=== added directory 'files'
104=== renamed file 'hooks/relation-changed' => 'hooks/amqp'
105--- hooks/relation-changed 2012-11-15 16:13:30 +0000
106+++ hooks/amqp 2013-02-22 17:25:28 +0000
107@@ -2,8 +2,6 @@
108
109 . $(dirname $0)/common
110
111-config=/var/www/daisy/local_config.py
112-
113 get_rabbit_settings () {
114 local rabbit_user="$(config-get amqp-user)"
115 local rabbit_vhost="$(config-get amqp-vhost)"
116@@ -24,20 +22,9 @@
117 save_setting amqp_username "$rabbit_user"
118 save_setting amqp_password "$rabbit_password"
119 save_setting amqp_vhost "$rabbit_vhost"
120-}
121
122-save_cassandra_settings () {
123- cassandrahost="$(relation-get private-address)"
124- if ! grep -qs 'cassandra_hosts' $config; then
125- echo "cassandra_hosts = ['$cassandrahost']" >> $config
126- else
127- sed -i "s,cassandra_hosts = .*,cassandra_hosts = ['$cassandrahost']," $config
128- fi
129- if "$(dirname $0)/create-keyspace" "$cassandrahost"; then
130- OOPS_KEYSPACE=crashdb OOPS_HOST="$cassandrahost" python \
131- /usr/share/pyshared/oopsrepository/schema.py
132- PYTHONPATH=/var/www/daisy python /var/www/daisy/schema.py
133- fi
134+ # Tell the WSGI server to reload, since we've modified $LOCAL_CONFIG_PATH.
135+ wsgi_reload
136 }
137
138 COMMAND="$(basename $0)"
139@@ -49,9 +36,6 @@
140 amqp-relation-changed)
141 save_rabbit_settings
142 ;;
143- db-relation-changed)
144- save_cassandra_settings
145- ;;
146 *)
147 juju-log "Command not recognized"
148 ;;
149
150=== modified symlink 'hooks/amqp-relation-changed'
151=== target changed u'relation-changed' => u'amqp'
152=== modified symlink 'hooks/amqp-relation-joined'
153=== target changed u'relation-changed' => u'amqp'
154=== added file 'hooks/cassandra'
155--- hooks/cassandra 1970-01-01 00:00:00 +0000
156+++ hooks/cassandra 2013-02-22 17:25:28 +0000
157@@ -0,0 +1,56 @@
158+#!/bin/sh -eux
159+
160+. $(dirname $0)/common
161+
162+address="$(relation-get private-address)"
163+COMMAND="$(basename $0)"
164+
165+if [ -n "$(config-get daisy-cassandra-host)" ]; then
166+ juju-log "A Cassandra host has been manually set. Ignoring the relation."
167+ exit 0
168+fi
169+
170+if [ -z "$address" ] && [ $COMMAND != "db-relation-broken" ]; then
171+ juju-log "No address provided."
172+ exit 0
173+fi
174+
175+if [ "$COMMAND" = "db-relation-departed" ]; then
176+ # First remove the address that just departed the relation, then remove the
177+ # trailing comma from the list, if one exists.
178+ sed -i -e "s|\(cassandra_hosts = .*\)'$address'[, ]*|\1|" \
179+ -e "s|, ]|]|" $LOCAL_CONFIG_PATH
180+
181+elif [ "$COMMAND" = "db-relation-joined" ]; then
182+ p="$LOCAL_CONFIG_PATH"
183+
184+ if ! grep -qs 'cassandra_hosts =' $p; then
185+ # We do not have a cassandra_hosts variable. Set one with a new list.
186+ echo "cassandra_hosts = ['$address']" >> $p
187+
188+ elif grep -qs "cassandra_hosts =.*']" $p; then
189+ # We already have at least one host. Put the new host on the end of the
190+ # list.
191+ sed -i "s|\(cassandra_hosts.*\)]|\1, '$address']|" $p
192+
193+ elif grep -qs "cassandra_hosts =.*\[[ *]*\]" $p; then
194+ # We have no hosts. Replace the entire line with a new single-element
195+ # list.
196+ sed -i "s|cassandra_hosts =.*|cassandra_hosts = ['$address']|" $p
197+ fi
198+
199+ if "$(dirname $0)/create-keyspace" "$address"; then
200+ OOPS_KEYSPACE=crashdb OOPS_HOST="$address" python \
201+ /usr/share/pyshared/oopsrepository/schema.py
202+ PYTHONPATH=$LOCAL_CONFIG_LOCATION:$CODE_LOCATION python \
203+ $CODE_LOCATION/daisy/schema.py
204+ fi
205+
206+elif [ "$COMMAND" = "db-relation-broken" ]; then
207+ sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" $LOCAL_CONFIG_PATH
208+fi
209+
210+# Tell the WSGI server to reload, since we've modified $LOCAL_CONFIG_PATH.
211+wsgi_reload
212+
213+exit 0
214
215=== modified file 'hooks/common'
216--- hooks/common 2012-10-10 10:45:43 +0000
217+++ hooks/common 2013-02-22 17:25:28 +0000
218@@ -1,13 +1,52 @@
219 #!/bin/sh
220
221-config=/var/www/daisy/local_config.py
222+BASEDIR="$(config-get basedir)"
223+INSTANCE_TYPE="$(config-get instance_type)"
224+USER_CODE_OWNER=$(config-get user_code_owner)
225+GROUP_CODE_OWNER=$(config-get group_code_owner)
226+USER_CODE_RUNNER=$(config-get user_code_runner)
227+GROUP_CODE_RUNNER=$(config-get group_code_runner)
228+DEPLOY_ROOT="/srv/$BASEDIR/$INSTANCE_TYPE"
229+CODE_LOCATION="$DEPLOY_ROOT/daisy"
230+LOCAL_CONFIG_LOCATION="$DEPLOY_ROOT/local_config"
231+LOCAL_CONFIG_PATH="$LOCAL_CONFIG_LOCATION/local_config.py"
232+OOPS_LOCAL="$DEPLOY_ROOT/oops-local"
233+LISTEN_PORT="$(config-get listen_port)"
234+LOG_DIR="/srv/$BASEDIR/$INSTANCE_TYPE-logs"
235
236 save_setting () {
237 key="$1"
238 value="$2"
239- if ! grep -qs "$key" $config; then
240- echo "$key = '$value'" >> $config
241- else
242- sed -i "s,$key = .*,$key = '$value'," $config
243- fi
244+ if ! grep -qs "$key" $LOCAL_CONFIG_PATH; then
245+ echo "$key = '$value'" >> $LOCAL_CONFIG_PATH
246+ else
247+ sed -i "s,$key = .*,$key = '$value'," $LOCAL_CONFIG_PATH
248+ fi
249+}
250+
251+save_cassandra () {
252+ value="$1"
253+ if ! grep -qs "cassandra_hosts" $LOCAL_CONFIG_PATH; then
254+ echo "cassandra_hosts = ['$value']" >> $LOCAL_CONFIG_PATH
255+ else
256+ sed -i "s,cassandra_hosts = .*,cassandra_hosts = ['$value']," \
257+ $LOCAL_CONFIG_PATH
258+ fi
259+}
260+
261+add_user () {
262+ local user="$1"
263+ local group="$2"
264+ id $user 2>/dev/null || adduser --quiet --system --disabled-password --ingroup $group $user
265+}
266+
267+add_group () {
268+ local group="$1"
269+ getent group | grep -qs "^$group:" || addgroup --quiet "$group"
270+}
271+
272+wsgi_reload () {
273+ for relid in $(relation-ids wsgi-file); do
274+ relation-set -r $relid wsgi_timestamp=$(date +%s)
275+ done
276 }
277
278=== modified file 'hooks/config-changed'
279--- hooks/config-changed 2012-10-10 09:35:32 +0000
280+++ hooks/config-changed 2013-02-22 17:25:28 +0000
281@@ -2,12 +2,36 @@
282
283 . $(dirname $0)/common
284
285+cassandra_host="$(config-get daisy-cassandra-host)"
286+
287+swift_bucket="$(config-get daisy-swift-bucket)"
288+os_auth_url="$(config-get daisy-openstack-auth-url)"
289+os_username="$(config-get daisy-openstack-username)"
290+os_password="$(config-get daisy-openstack-password)"
291+os_tenant="$(config-get daisy-openstack-tenant)"
292+os_region="$(config-get daisy-openstack-region)"
293+[ -n "$swift_bucket" ] && save_setting swift_bucket "$swift_bucket"
294+[ -n "$os_auth_url" ] && save_setting os_auth_url "$os_auth_url"
295+[ -n "$os_username" ] && save_setting os_username "$os_username"
296+[ -n "$os_password" ] && save_setting os_password "$os_password"
297+[ -n "$os_tenant" ] && save_setting os_tenant_name "$os_tenant"
298+[ -n "$os_region" ] && save_setting os_region_name "$os_region"
299+
300 aws_secret_key="$(config-get daisy-aws-secret-key)"
301 aws_access_key="$(config-get daisy-aws-access-key)"
302-ec2_host="$(config-get daisy-ec2-host)"
303-ec2_bucket="$(config-get daisy-ec2-bucket)"
304-
305+ec2_host="$(config-get daisy-s3-host)"
306+ec2_bucket="$(config-get daisy-s3-bucket)"
307 [ -n "$aws_secret_key" ] && save_setting aws_secret_key "$aws_secret_key"
308 [ -n "$aws_access_key" ] && save_setting aws_access_key "$aws_access_key"
309 [ -n "$ec2_host" ] && save_setting ec2_host "$ec2_host"
310 [ -n "$ec2_bucket" ] && save_setting ec2_bucket "$ec2_bucket"
311+
312+# If the user has set daisy-cassandra-host to null, set cassandra_hosts back to
313+# an empty list.
314+[ -n "$cassandra_host" ] && save_cassandra "$cassandra_host" #|| \
315+ #sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" $LOCAL_CONFIG_PATH
316+
317+# Tell the WSGI server to reload, since we've modified $LOCAL_CONFIG_PATH.
318+wsgi_reload
319+
320+exit 0
321
322=== added file 'hooks/daisy-relation-changed'
323--- hooks/daisy-relation-changed 1970-01-01 00:00:00 +0000
324+++ hooks/daisy-relation-changed 2013-02-22 17:25:28 +0000
325@@ -0,0 +1,7 @@
326+#!/bin/sh -eux
327+
328+. hooks/common
329+
330+hostname="$(unit-get private-address)"
331+juju-log "Setting website URL to $hostname:$LISTEN_PORT"
332+relation-set port=$LISTEN_PORT hostname=$hostname
333
334=== added symlink 'hooks/daisy-relation-joined'
335=== target is u'daisy-relation-changed'
336=== added symlink 'hooks/db-relation-broken'
337=== target is u'cassandra'
338=== removed symlink 'hooks/db-relation-changed'
339=== target was u'relation-changed'
340=== added symlink 'hooks/db-relation-departed'
341=== target is u'cassandra'
342=== added symlink 'hooks/db-relation-joined'
343=== target is u'cassandra'
344=== modified file 'hooks/install'
345--- hooks/install 2012-11-15 12:26:48 +0000
346+++ hooks/install 2013-02-22 17:25:28 +0000
347@@ -1,32 +1,44 @@
348 #!/bin/sh
349 set -eux
350-sudo add-apt-repository ppa:ev/whoopsie-daisy
351-apt-get update
352-DEBCONF_FRONTEND=noninteractive apt-get -y install daisy-dependencies
353-# Enable mod_rewrite.
354-a2enmod rewrite
355-[ -e /srv/local-oopses-whoopsie ] || mkdir /srv/local-oopses-whoopsie
356-chown www-data:users /srv/local-oopses-whoopsie
357-cat > /etc/apache2/sites-enabled/000-default << EOF
358-<VirtualHost *:80>
359- ServerAdmin webmaster@localhost
360-
361- DocumentRoot /var/www/daisy
362- WSGIDaemonProcess localhost python-path=/var/www/daisy:/var/www
363- WSGIProcessGroup localhost
364- WSGIApplicationGroup localhost
365- WSGIScriptAlias / /var/www/daisy/submit.wsgi
366- RewriteEngine on
367- RewriteRule ^/([^/]+)/submit-core/([^/]+)/([^/]+) /submit_core.wsgi?uuid=\$1&arch=\$2&systemuuid=\$3 [L]
368- <Directory /var/www/daisy>
369- SetHandler wsgi-script
370- </Directory>
371- ErrorLog /var/log/apache2/error.log
372- LogLevel warn
373- CustomLog /var/log/apache2/access.log combined
374-</VirtualHost>
375-EOF
376-[ -e /var/www/daisy ] || bzr branch lp:~ev/daisy/s3 /var/www/daisy
377-/etc/init.d/apache2 restart
378-
379-cp /var/www/daisy/configuration.py /var/www/daisy/local_config.py
380+
381+. hooks/common
382+
383+sudo apt-add-repository "$(config-get repository)"
384+sudo apt-get update
385+DEBCONF_FRONTEND=noninteractive sudo apt-get -y install daisy-dependencies
386+
387+# Create groups
388+add_group "$GROUP_CODE_OWNER"
389+add_group "$GROUP_CODE_RUNNER"
390+
391+# Create users
392+add_user "$USER_CODE_OWNER" "$GROUP_CODE_OWNER"
393+add_user "$USER_CODE_RUNNER" "$GROUP_CODE_RUNNER"
394+
395+# Create directories
396+mkdir -p "$CODE_LOCATION" "$LOCAL_CONFIG_LOCATION" "$OOPS_LOCAL" "$LOG_DIR"
397+
398+# Unpack tarred Daisy code
399+charm_dir="$(pwd)"
400+tarball="$charm_dir/files/daisy.tgz"
401+
402+if [ -f "$tarball" ]; then
403+ tar -C "$CODE_LOCATION" -xvf "$tarball"
404+fi
405+
406+if [ ! -e "$LOCAL_CONFIG_PATH" ]; then
407+ cp "$CODE_LOCATION/daisy/configuration.py" "$LOCAL_CONFIG_PATH"
408+fi
409+
410+# Reset the Cassandra hosts setting. This may have been established by a
411+# previous charm, but its contents are now invalid until the config-changed or
412+# db-relation-* hooks fires. Its default value of 127.0.0.1 would persist
413+# across db-relation-joined and db-relation-departed calls if left set.
414+sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" "$LOCAL_CONFIG_PATH"
415+
416+save_setting "oops_repository" "$OOPS_LOCAL"
417+
418+chown -R $USER_CODE_OWNER:$USER_CODE_RUNNER "/srv/$BASEDIR"
419+chown -R $USER_CODE_RUNNER:$GROUP_CODE_RUNNER "$OOPS_LOCAL"
420+
421+exit 0
422
423=== added file 'hooks/wsgi-file-relation-changed'
424--- hooks/wsgi-file-relation-changed 1970-01-01 00:00:00 +0000
425+++ hooks/wsgi-file-relation-changed 2013-02-22 17:25:28 +0000
426@@ -0,0 +1,22 @@
427+#!/bin/sh -eux
428+
429+. hooks/common
430+
431+set +u
432+RID="$1"
433+set -u
434+OPTION=
435+
436+if [ -n "$RID" ]; then
437+ OPTION="-r $RID"
438+fi
439+
440+relation-set $OPTION working_dir=$CODE_LOCATION
441+relation-set $OPTION python_path="$CODE_LOCATION:$LOCAL_CONFIG_LOCATION"
442+relation-set $OPTION wsgi_worker_class='gevent_wsgi'
443+relation-set $OPTION wsgi_user="$USER_CODE_RUNNER"
444+relation-set $OPTION wsgi_group="$GROUP_CODE_RUNNER"
445+relation-set $OPTION port="$LISTEN_PORT"
446+relation-set $OPTION wsgi_access_logfile="$LOG_DIR/daisy-access.log"
447+relation-set $OPTION wsgi_extra="'--error-logfile=$LOG_DIR/daisy-error.log',"
448+relation-set $OPTION wsgi_wsgi_file='daisy.wsgi:application'
449
450=== added symlink 'hooks/wsgi-file-relation-joined'
451=== target is u'wsgi-file-relation-changed'
452=== modified file 'metadata.yaml'
453--- metadata.yaml 2012-10-05 13:32:03 +0000
454+++ metadata.yaml 2013-02-22 17:25:28 +0000
455@@ -1,8 +1,15 @@
456 name: daisy
457-summary: "Daisy error reporting server"
458+summary: "Daisy for the Ubuntu Error Tracker"
459 description: |
460- Installs the Daisy error reporting server for Ubuntu, relates to Cassandra
461- and RabbitMQ.
462+ Deploys the Daisy component of the Ubuntu Error Tracker. Daisy is
463+ responsible for receiving error reports from Ubuntu systems and writing
464+ them into a Cassandra database.
465+provides:
466+ wsgi-file:
467+ interface: wsgi
468+ scope: container
469+ daisy:
470+ interface: http
471 requires:
472 db:
473 interface: cassandra
474
475=== modified file 'revision'
476--- revision 2012-11-27 18:15:51 +0000
477+++ revision 2013-02-22 17:25:28 +0000
478@@ -1,1 +1,1 @@
479-92
480+146

Subscribers

People subscribed via source and target branches

to all changes: