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

Proposed by Evan
Status: Merged
Merged at revision: 20
Proposed branch: lp:~ev/charms/precise/daisy-retracer/prodstack-prep
Merge into: lp:~daisy-pluckers/charms/precise/daisy-retracer/trunk
Diff against target: 518 lines (+292/-127)
8 files modified
config.yaml (+67/-4)
hooks/amqp (+41/-0)
hooks/cassandra (+50/-56)
hooks/common (+53/-4)
hooks/config-changed (+26/-18)
hooks/install (+54/-35)
hooks/retracer.conf (+0/-9)
revision (+1/-1)
To merge this branch: bzr merge lp:~ev/charms/precise/daisy-retracer/prodstack-prep
Reviewer Review Type Date Requested Status
Daisy Pluckers Pending
Review via email: mp+150109@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-12-12 15:11:24 +0000
3+++ config.yaml 2013-02-22 17:21:30 +0000
4@@ -1,4 +1,28 @@
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 amqp-user:
31 type: string
32 default: 'daisy'
33@@ -15,15 +39,54 @@
34 type: string
35 default: ''
36 description: The AWS access key (EC2_ACCESS_KEY).
37- daisy-retracer-ec2-host:
38+ daisy-retracer-s3-host:
39 type: string
40 default: ''
41- description: The EC2 IP address.
42- daisy-retracer-ec2-bucket:
43+ description: The S3 IP address.
44+ daisy-retracer-s3-bucket:
45 type: string
46 default: 'daisy_core_files'
47- description: The EC2 bucket.
48+ description: The S3 bucket.
49+ daisy-retracer-openstack-auth-url:
50+ type: string
51+ default: ''
52+ description: |
53+ The OpenStack authentication URL, e.g.:
54+ https://keystone.yourdomain.com:443/v2.0/
55+ daisy-retracer-openstack-username:
56+ type: string
57+ default: ''
58+ description: The OpenStack username to authenticate with.
59+ daisy-retracer-openstack-password:
60+ type: string
61+ default: ''
62+ description: The OpenStack password to authenticate with.
63+ daisy-retracer-openstack-tenant:
64+ type: string
65+ default: ''
66+ description: |
67+ The OpenStack tenant to use, e.g.: yourname_project.
68+ daisy-retracer-openstack-region:
69+ type: string
70+ default: ''
71+ description: The OpenStack region to use.
72+ daisy-retracer-swift-bucket:
73+ type: string
74+ default: ''
75+ description: |
76+ The OpenStack Swift bucket to use, e.g.: daisy_core_files.
77+ Setting this will use Swift instead of S3 for storing core files.
78+ daisy-retracer-cassandra-host:
79+ type: string
80+ default: ''
81+ description: |
82+ Override relations to Cassandra with a specific host address. This
83+ is a temporary measure until cross-environment relations are ready.
84 daisy-retracer-architectures:
85 type: string
86 default: 'i386 amd64 armhf'
87 description: Space separated list of architectures for which to process reports.
88+ repository:
89+ type: string
90+ default: 'ppa:daisy-pluckers/prodstack-prep'
91+ description: The location for the daisy-dependencies package.
92
93=== added directory 'files'
94=== added file 'hooks/amqp'
95--- hooks/amqp 1970-01-01 00:00:00 +0000
96+++ hooks/amqp 2013-02-22 17:21:30 +0000
97@@ -0,0 +1,41 @@
98+#!/bin/sh -eux
99+
100+. $(dirname $0)/common
101+
102+get_rabbit_settings () {
103+ local rabbit_user="$(config-get amqp-user)"
104+ local rabbit_vhost="$(config-get amqp-vhost)"
105+ relation-set username="$rabbit_user"
106+ relation-set vhost="$rabbit_vhost"
107+}
108+
109+save_rabbit_settings () {
110+ local rabbit_user="$(config-get amqp-user)"
111+ local rabbit_vhost="$(config-get amqp-vhost)"
112+ local rabbit_host="$(relation-get private-address)"
113+ local rabbit_password="$(relation-get password)"
114+ if [ -z "$rabbit_host" ] || [ -z "$rabbit_password" ]; then
115+ juju-log "Missing AMQP host or password."
116+ exit 0
117+ fi
118+ save_setting amqp_host "$rabbit_host"
119+ save_setting amqp_username "$rabbit_user"
120+ save_setting amqp_password "$rabbit_password"
121+ save_setting amqp_vhost "$rabbit_vhost"
122+
123+ retracer_restart
124+}
125+
126+COMMAND="$(basename $0)"
127+
128+case "$COMMAND" in
129+ amqp-relation-joined)
130+ get_rabbit_settings
131+ ;;
132+ amqp-relation-changed)
133+ save_rabbit_settings
134+ ;;
135+ *)
136+ juju-log "Command not recognized"
137+ ;;
138+esac
139
140=== modified symlink 'hooks/amqp-relation-changed'
141=== target changed u'relation-changed' => u'amqp'
142=== modified symlink 'hooks/amqp-relation-joined'
143=== target changed u'relation-changed' => u'amqp'
144=== renamed file 'hooks/relation-changed' => 'hooks/cassandra'
145--- hooks/relation-changed 2012-12-13 10:14:41 +0000
146+++ hooks/cassandra 2013-02-22 17:21:30 +0000
147@@ -2,61 +2,55 @@
148
149 . $(dirname $0)/common
150
151-cassandrahost="$(relation-get private-address)"
152-nfshost="$(relation-get private-address)"
153-rabbithost="$(relation-get private-address)"
154-
155-get_rabbit_settings () {
156- local rabbit_user="$(config-get amqp-user)"
157- local rabbit_vhost="$(config-get amqp-vhost)"
158- relation-set username="$rabbit_user"
159- relation-set vhost="$rabbit_vhost"
160-}
161-
162-save_rabbit_settings () {
163- local rabbit_user="$(config-get amqp-user)"
164- local rabbit_vhost="$(config-get amqp-vhost)"
165- local rabbit_host="$(relation-get private-address)"
166- local rabbit_password="$(relation-get password)"
167- if [ -z "$rabbit_host" ] || [ -z "$rabbit_password" ]; then
168- juju-log "Missing AMQP host or password."
169- exit 0
170- fi
171- save_setting amqp_host "$rabbit_host"
172- save_setting amqp_username "$rabbit_user"
173- save_setting amqp_password "$rabbit_password"
174- save_setting amqp_vhost "$rabbit_vhost"
175-}
176-
177-save_cassandra_settings () {
178- if ! grep -qs 'cassandra_hosts' $config; then
179- echo "cassandra_hosts = ['$cassandrahost']" >> $config
180- else
181- sed -i "s,cassandra_hosts = .*,cassandra_hosts = ['$cassandrahost']," $config
182- fi
183-}
184-
185+address="$(relation-get private-address)"
186 COMMAND="$(basename $0)"
187
188-case "$COMMAND" in
189- amqp-relation-joined)
190- get_rabbit_settings
191- ;;
192- amqp-relation-changed)
193- save_rabbit_settings
194- ;;
195- db-relation-changed)
196- save_cassandra_settings
197- ;;
198- *)
199- juju-log "Command not recognized"
200- ;;
201-esac
202-
203-if [ -n "$cassandrahost" ] && [ -n "$rabbithost" ]; then
204- juju-log "Restarting all retracers"
205- for job in `(cd /etc/init; ls retracer*.conf)`; do
206- stop ${job%.conf} || true
207- start ${job%.conf}
208- done
209-fi
210+if [ -n "$(config-get daisy-cassandra-host)" ]; then
211+ juju-log "A Cassandra host has been manually set. Ignoring the relation."
212+ exit 0
213+fi
214+
215+if [ -z "$address" ] && [ $COMMAND != "db-relation-broken" ]; then
216+ juju-log "No address provided."
217+ exit 0
218+fi
219+
220+if [ "$COMMAND" = "db-relation-departed" ]; then
221+ # First remove the address that just departed the relation, then remove the
222+ # trailing comma from the list, if one exists.
223+ sed -i -e "s|\(cassandra_hosts = .*\)'$address'[, ]*|\1|" \
224+ -e "s|, ]|]|" $LOCAL_CONFIG_PATH
225+
226+elif [ "$COMMAND" = "db-relation-joined" ]; then
227+ p="$LOCAL_CONFIG_PATH"
228+
229+ if ! grep -qs 'cassandra_hosts =' $p; then
230+ # We do not have a cassandra_hosts variable. Set one with a new list.
231+ echo "cassandra_hosts = ['$address']" >> $p
232+
233+ elif grep -qs "cassandra_hosts =.*']" $p; then
234+ # We already have at least one host. Put the new host on the end of the
235+ # list.
236+ sed -i "s|\(cassandra_hosts.*\)]|\1, '$address']|" $p
237+
238+ elif grep -qs "cassandra_hosts =.*\[[ *]*\]" $p; then
239+ # We have no hosts. Replace the entire line with a new single-element
240+ # list.
241+ sed -i "s|cassandra_hosts =.*|cassandra_hosts = ['$address']|" $p
242+ fi
243+
244+ if "$(dirname $0)/create-keyspace" "$address"; then
245+ OOPS_KEYSPACE=crashdb OOPS_HOST="$address" python \
246+ /usr/share/pyshared/oopsrepository/schema.py
247+ PYTHONPATH=$LOCAL_CONFIG_LOCATION:$CODE_LOCATION python \
248+ $CODE_LOCATION/daisy/schema.py
249+ fi
250+
251+elif [ "$COMMAND" = "db-relation-broken" ]; then
252+ sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" $LOCAL_CONFIG_PATH
253+fi
254+
255+# Restart the retracer, since we've changed its configuration.
256+retracer_restart
257+
258+exit 0
259
260=== modified file 'hooks/common'
261--- hooks/common 2012-10-10 09:38:57 +0000
262+++ hooks/common 2013-02-22 17:21:30 +0000
263@@ -1,13 +1,62 @@
264 #!/bin/sh
265
266-config=/var/retracer/daisy/local_config.py
267+BASEDIR="$(config-get basedir)"
268+INSTANCE_TYPE="$(config-get instance_type)"
269+USER_CODE_OWNER=$(config-get user_code_owner)
270+GROUP_CODE_OWNER=$(config-get group_code_owner)
271+USER_CODE_RUNNER=$(config-get user_code_runner)
272+GROUP_CODE_RUNNER=$(config-get group_code_runner)
273+ARCHITECTURES="$(config-get daisy-retracer-architectures)"
274+DEPLOY_ROOT="/srv/$BASEDIR/$INSTANCE_TYPE"
275+CODE_LOCATION="$DEPLOY_ROOT/daisy"
276+LOCAL_CONFIG_LOCATION="$DEPLOY_ROOT/local_config"
277+LOCAL_CONFIG_PATH="$LOCAL_CONFIG_LOCATION/local_config.py"
278+LOG_DIR="/srv/$BASEDIR/$INSTANCE_TYPE-logs"
279+APPORT_LOCATION="$DEPLOY_ROOT/apport"
280+CACHE_DIR="$DEPLOY_ROOT/cache"
281
282 save_setting () {
283 key="$1"
284 value="$2"
285- if ! grep -qs "$key" $config; then
286- echo "$key = '$value'" >> $config
287+ if ! grep -qs "$key" $LOCAL_CONFIG_PATH; then
288+ echo "$key = '$value'" >> $LOCAL_CONFIG_PATH
289 else
290- sed -i "s,$key = .*,$key = '$value'," $config
291+ sed -i "s,$key = .*,$key = '$value'," $LOCAL_CONFIG_PATH
292 fi
293 }
294+
295+add_user () {
296+ local user="$1"
297+ local group="$2"
298+ id $user 2>/dev/null || adduser --quiet --system --disabled-password --ingroup $group $user
299+}
300+
301+add_group () {
302+ local group="$1"
303+ getent group | grep -qs "^$group:" || addgroup --quiet "$group"
304+}
305+
306+retracer_restart () {
307+ # stop all retracers
308+ juju-log "Stopping all retracers"
309+ for job in `(cd /etc/init; ls retracer*.conf)`; do
310+ stop ${job%.conf} || true
311+ rm /etc/init/$job
312+ done
313+
314+ # create upstart jobs for configured architectures, and start them
315+ for arch in $ARCHITECTURES; do
316+ juju-log "Creating upstart job for $arch retracer"
317+ cat > /etc/init/retracer-$arch.conf << EOF
318+description "error tracker retracer for $arch"
319+env PYTHONPATH=$LOCAL_CONFIG_LOCATION:$CODE_LOCATION:$APPORT_LOCATION:$DEPLOY_ROOT
320+export PYTHONPATH
321+env PATH=$APPORT_LOCATION/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
322+export PATH
323+exec $CODE_LOCATION/daisy/retracer.py --config-dir $CODE_LOCATION/retracer/config --sandbox-dir $CACHE_DIR --output $LOG_DIR/retracer-$arch.log --architecture $arch
324+EOF
325+ juju-log "Starting $arch retracer"
326+ start retracer-$arch
327+
328+ done
329+}
330
331=== modified file 'hooks/config-changed'
332--- hooks/config-changed 2012-12-12 15:11:24 +0000
333+++ hooks/config-changed 2013-02-22 17:21:30 +0000
334@@ -1,20 +1,27 @@
335-#!/bin/sh
336-set -eu
337+#!/bin/sh -eux
338
339 . $(dirname $0)/common
340
341-# stop all retracers
342-juju-log "Stopping all retracers"
343-for job in `(cd /etc/init; ls retracer*.conf)`; do
344- stop ${job%.conf} || true
345- rm /etc/init/$job
346-done
347-
348 juju-log "Updating configuration settings"
349+
350+swift_bucket="$(config-get daisy-retracer-swift-bucket)"
351+os_auth_url="$(config-get daisy-retracer-openstack-auth-url)"
352+os_username="$(config-get daisy-retracer-openstack-username)"
353+os_password="$(config-get daisy-retracer-openstack-password)"
354+os_tenant="$(config-get daisy-retracer-openstack-tenant)"
355+os_region="$(config-get daisy-retracer-openstack-region)"
356+[ -n "$swift_bucket" ] && save_setting swift_bucket "$swift_bucket"
357+[ -n "$os_auth_url" ] && save_setting os_auth_url "$os_auth_url"
358+[ -n "$os_username" ] && save_setting os_username "$os_username"
359+[ -n "$os_password" ] && save_setting os_password "$os_password"
360+[ -n "$os_tenant" ] && save_setting os_tenant_name "$os_tenant"
361+[ -n "$os_region" ] && save_setting os_region_name "$os_region"
362+
363 aws_secret_key="$(config-get daisy-retracer-aws-secret-key)"
364 aws_access_key="$(config-get daisy-retracer-aws-access-key)"
365-ec2_host="$(config-get daisy-retracer-ec2-host)"
366-ec2_bucket="$(config-get daisy-retracer-ec2-bucket)"
367+ec2_host="$(config-get daisy-retracer-s3-host)"
368+ec2_bucket="$(config-get daisy-retracer-s3-bucket)"
369+cassandra_host="$(config-get daisy-retracer-cassandra-host)"
370 architectures="$(config-get daisy-retracer-architectures)"
371
372 [ -n "$aws_secret_key" ] && save_setting aws_secret_key "$aws_secret_key"
373@@ -22,10 +29,11 @@
374 [ -n "$ec2_host" ] && save_setting ec2_host "$ec2_host"
375 [ -n "$ec2_bucket" ] && save_setting ec2_bucket "$ec2_bucket"
376
377-# create upstart jobs for configured architectures, and start them
378-for arch in $architectures; do
379- juju-log "Creating upstart job for $arch retracer"
380- sed "s/@ARCH@/$arch/g" hooks/retracer.conf > /etc/init/retracer-$arch.conf
381- juju-log "Starting $arch retracer"
382- start retracer-$arch
383-done
384+# If the user has set daisy-cassandra-host to null, set cassandra_hosts back to
385+# an empty list.
386+[ -n "$cassandra_host" ] && save_cassandra "$cassandra_host" #|| \
387+ #sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" $LOCAL_CONFIG_PATH
388+
389+retracer_restart
390+
391+exit 0
392
393=== added symlink 'hooks/db-relation-broken'
394=== target is u'cassandra'
395=== removed symlink 'hooks/db-relation-changed'
396=== target was u'relation-changed'
397=== added symlink 'hooks/db-relation-departed'
398=== target is u'cassandra'
399=== added symlink 'hooks/db-relation-joined'
400=== target is u'cassandra'
401=== modified file 'hooks/install'
402--- hooks/install 2012-12-12 15:11:24 +0000
403+++ hooks/install 2013-02-22 17:21:30 +0000
404@@ -1,37 +1,56 @@
405 #!/bin/sh
406-set -e
407-
408-mkdir -p /var/retracer/cache
409-
410-# TODO: move remaining packages over to daisy-seeds PPA
411-add-apt-repository ppa:ev/whoopsie-daisy
412-add-apt-repository ppa:daisy-pluckers/daisy-seeds
413+set -eux
414+
415+. hooks/common
416+
417+add-apt-repository "$(config-get repository)"
418 apt-get update
419-# debootstrap is for building the chroot
420-apt-get install -y retracer-dependencies debootstrap
421-
422-# get latest release of Apport
423-if [ -d /var/retracer/apport ]; then
424- cd /var/retracer/apport
425- bzr pull
426-else
427- bzr branch lp:apport /var/retracer/apport
428- cd /var/retracer/apport
429-fi
430-LATEST_TAG=`bzr tags | sort -nrk 2 | head -n1 | awk '{print $1}'`
431-bzr uncommit --force -r tag:$LATEST_TAG
432-bzr revert --no-backup
433-bzr clean-tree --ignored --unknown --force
434-# set up the apt/dpkg Apport packaging backend; setup.py build would need more
435-# dependencies
436-rm -f apport/packaging_impl.py
437-ln -s ../backends/packaging-apt-dpkg.py apport/packaging_impl.py
438-cd -
439-
440-# Retracer config
441-if [ -d /var/retracer/daisy ]; then
442- (cd /var/retracer/daisy; bzr pull)
443-else
444- bzr branch lp:~ev/daisy/s3 /var/retracer/daisy
445- cp /var/retracer/daisy/configuration.py /var/retracer/daisy/local_config.py
446-fi
447+apt-get install -y retracer-dependencies
448+
449+# Create groups
450+add_group "$GROUP_CODE_OWNER"
451+add_group "$GROUP_CODE_RUNNER"
452+
453+# Create users
454+add_user "$USER_CODE_OWNER" "$GROUP_CODE_OWNER"
455+add_user "$USER_CODE_RUNNER" "$GROUP_CODE_RUNNER"
456+
457+# Create directories
458+mkdir -p "$CODE_LOCATION" "$LOCAL_CONFIG_LOCATION" "$LOG_DIR" "$APPORT_LOCATION" "$CACHE_DIR"
459+
460+# Unpack tarred Daisy code
461+charm_dir="$(pwd)"
462+tarball="$charm_dir/files/daisy.tgz"
463+
464+if [ -f "$tarball" ]; then
465+ tar -C "$CODE_LOCATION" -xvf "$tarball"
466+fi
467+
468+if [ ! -e "$LOCAL_CONFIG_PATH" ]; then
469+ cp "$CODE_LOCATION/daisy/configuration.py" "$LOCAL_CONFIG_PATH"
470+fi
471+
472+# Unpack tarred Apport snapshot
473+apport="$charm_dir/files/apport.tgz"
474+
475+if [ -f "$apport" ]; then
476+ tar -C "$APPORT_LOCATION" -xvf "$apport"
477+
478+ # set up the apt/dpkg Apport packaging backend; setup.py build would need more
479+ # dependencies
480+ cd "$APPORT_LOCATION"
481+ rm -f apport/packaging_impl.py
482+ ln -s ../backends/packaging-apt-dpkg.py apport/packaging_impl.py
483+ cd -
484+fi
485+
486+# Reset the Cassandra hosts setting. This may have been established by a
487+# previous charm, but its contents are now invalid until the config-changed or
488+# db-relation-* hooks fires. Its default value of 127.0.0.1 would persist
489+# across db-relation-joined and db-relation-departed calls if left set.
490+sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" "$LOCAL_CONFIG_PATH"
491+
492+chown -R $USER_CODE_OWNER:$USER_CODE_RUNNER "/srv/$BASEDIR"
493+chown -R $USER_CODE_RUNNER:$GROUP_CODE_RUNNER "$CACHE_DIR"
494+
495+exit 0
496
497=== removed symlink 'hooks/nfs-relation-changed'
498=== target was u'relation-changed'
499=== removed file 'hooks/retracer.conf'
500--- hooks/retracer.conf 2012-12-12 15:11:24 +0000
501+++ hooks/retracer.conf 1970-01-01 00:00:00 +0000
502@@ -1,9 +0,0 @@
503-description "error tracker retracer for @ARCH@"
504-
505-# Use upstart because James prefers it over supervisord. jjo had a reason for
506-# using supervisord - touch base.
507-env PYTHONPATH=/var/retracer/daisy:/var/retracer/apport:/var/retracer
508-export PYTHONPATH
509-env PATH=/var/retracer/apport/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
510-export PATH
511-exec /var/retracer/daisy/process_core.py --config-dir /var/retracer/daisy/retracer/config --sandbox-dir /var/retracer/cache --output /var/log/retracer-@ARCH@.log --architecture @ARCH@
512
513=== modified file 'revision'
514--- revision 2012-12-13 10:14:41 +0000
515+++ revision 2013-02-22 17:21:30 +0000
516@@ -1,1 +1,1 @@
517-54
518+59

Subscribers

People subscribed via source and target branches

to all changes: