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
=== modified file 'config.yaml'
--- config.yaml 2012-12-12 15:11:24 +0000
+++ config.yaml 2013-02-22 17:21:30 +0000
@@ -1,4 +1,28 @@
1options:1options:
2 basedir:
3 default: "daisy.ubuntu.com"
4 type: string
5 description: Base directory for code
6 instance_type:
7 default: "production"
8 type: string
9 description: Instance type
10 user_code_runner:
11 default: "whoopsie"
12 type: string
13 description: The user that runs the code
14 group_code_runner:
15 default: "whoopsie"
16 type: string
17 description: The group that runs the code
18 user_code_owner:
19 default: "webops_deploy"
20 type: string
21 description: The user that owns the code
22 group_code_owner:
23 default: "webops_deploy"
24 type: string
25 description: The group that owns the code
2 amqp-user:26 amqp-user:
3 type: string27 type: string
4 default: 'daisy'28 default: 'daisy'
@@ -15,15 +39,54 @@
15 type: string39 type: string
16 default: ''40 default: ''
17 description: The AWS access key (EC2_ACCESS_KEY).41 description: The AWS access key (EC2_ACCESS_KEY).
18 daisy-retracer-ec2-host:42 daisy-retracer-s3-host:
19 type: string43 type: string
20 default: ''44 default: ''
21 description: The EC2 IP address.45 description: The S3 IP address.
22 daisy-retracer-ec2-bucket:46 daisy-retracer-s3-bucket:
23 type: string47 type: string
24 default: 'daisy_core_files'48 default: 'daisy_core_files'
25 description: The EC2 bucket.49 description: The S3 bucket.
50 daisy-retracer-openstack-auth-url:
51 type: string
52 default: ''
53 description: |
54 The OpenStack authentication URL, e.g.:
55 https://keystone.yourdomain.com:443/v2.0/
56 daisy-retracer-openstack-username:
57 type: string
58 default: ''
59 description: The OpenStack username to authenticate with.
60 daisy-retracer-openstack-password:
61 type: string
62 default: ''
63 description: The OpenStack password to authenticate with.
64 daisy-retracer-openstack-tenant:
65 type: string
66 default: ''
67 description: |
68 The OpenStack tenant to use, e.g.: yourname_project.
69 daisy-retracer-openstack-region:
70 type: string
71 default: ''
72 description: The OpenStack region to use.
73 daisy-retracer-swift-bucket:
74 type: string
75 default: ''
76 description: |
77 The OpenStack Swift bucket to use, e.g.: daisy_core_files.
78 Setting this will use Swift instead of S3 for storing core files.
79 daisy-retracer-cassandra-host:
80 type: string
81 default: ''
82 description: |
83 Override relations to Cassandra with a specific host address. This
84 is a temporary measure until cross-environment relations are ready.
26 daisy-retracer-architectures:85 daisy-retracer-architectures:
27 type: string86 type: string
28 default: 'i386 amd64 armhf'87 default: 'i386 amd64 armhf'
29 description: Space separated list of architectures for which to process reports.88 description: Space separated list of architectures for which to process reports.
89 repository:
90 type: string
91 default: 'ppa:daisy-pluckers/prodstack-prep'
92 description: The location for the daisy-dependencies package.
3093
=== added directory 'files'
=== added file 'hooks/amqp'
--- hooks/amqp 1970-01-01 00:00:00 +0000
+++ hooks/amqp 2013-02-22 17:21:30 +0000
@@ -0,0 +1,41 @@
1#!/bin/sh -eux
2
3. $(dirname $0)/common
4
5get_rabbit_settings () {
6 local rabbit_user="$(config-get amqp-user)"
7 local rabbit_vhost="$(config-get amqp-vhost)"
8 relation-set username="$rabbit_user"
9 relation-set vhost="$rabbit_vhost"
10}
11
12save_rabbit_settings () {
13 local rabbit_user="$(config-get amqp-user)"
14 local rabbit_vhost="$(config-get amqp-vhost)"
15 local rabbit_host="$(relation-get private-address)"
16 local rabbit_password="$(relation-get password)"
17 if [ -z "$rabbit_host" ] || [ -z "$rabbit_password" ]; then
18 juju-log "Missing AMQP host or password."
19 exit 0
20 fi
21 save_setting amqp_host "$rabbit_host"
22 save_setting amqp_username "$rabbit_user"
23 save_setting amqp_password "$rabbit_password"
24 save_setting amqp_vhost "$rabbit_vhost"
25
26 retracer_restart
27}
28
29COMMAND="$(basename $0)"
30
31case "$COMMAND" in
32 amqp-relation-joined)
33 get_rabbit_settings
34 ;;
35 amqp-relation-changed)
36 save_rabbit_settings
37 ;;
38 *)
39 juju-log "Command not recognized"
40 ;;
41esac
042
=== modified symlink 'hooks/amqp-relation-changed'
=== target changed u'relation-changed' => u'amqp'
=== modified symlink 'hooks/amqp-relation-joined'
=== target changed u'relation-changed' => u'amqp'
=== renamed file 'hooks/relation-changed' => 'hooks/cassandra'
--- hooks/relation-changed 2012-12-13 10:14:41 +0000
+++ hooks/cassandra 2013-02-22 17:21:30 +0000
@@ -2,61 +2,55 @@
22
3. $(dirname $0)/common3. $(dirname $0)/common
44
5cassandrahost="$(relation-get private-address)"5address="$(relation-get private-address)"
6nfshost="$(relation-get private-address)"
7rabbithost="$(relation-get private-address)"
8
9get_rabbit_settings () {
10 local rabbit_user="$(config-get amqp-user)"
11 local rabbit_vhost="$(config-get amqp-vhost)"
12 relation-set username="$rabbit_user"
13 relation-set vhost="$rabbit_vhost"
14}
15
16save_rabbit_settings () {
17 local rabbit_user="$(config-get amqp-user)"
18 local rabbit_vhost="$(config-get amqp-vhost)"
19 local rabbit_host="$(relation-get private-address)"
20 local rabbit_password="$(relation-get password)"
21 if [ -z "$rabbit_host" ] || [ -z "$rabbit_password" ]; then
22 juju-log "Missing AMQP host or password."
23 exit 0
24 fi
25 save_setting amqp_host "$rabbit_host"
26 save_setting amqp_username "$rabbit_user"
27 save_setting amqp_password "$rabbit_password"
28 save_setting amqp_vhost "$rabbit_vhost"
29}
30
31save_cassandra_settings () {
32 if ! grep -qs 'cassandra_hosts' $config; then
33 echo "cassandra_hosts = ['$cassandrahost']" >> $config
34 else
35 sed -i "s,cassandra_hosts = .*,cassandra_hosts = ['$cassandrahost']," $config
36 fi
37}
38
39COMMAND="$(basename $0)"6COMMAND="$(basename $0)"
407
41case "$COMMAND" in8if [ -n "$(config-get daisy-cassandra-host)" ]; then
42 amqp-relation-joined)9 juju-log "A Cassandra host has been manually set. Ignoring the relation."
43 get_rabbit_settings10 exit 0
44 ;;11fi
45 amqp-relation-changed)12
46 save_rabbit_settings13if [ -z "$address" ] && [ $COMMAND != "db-relation-broken" ]; then
47 ;;14 juju-log "No address provided."
48 db-relation-changed)15 exit 0
49 save_cassandra_settings16fi
50 ;;17
51 *)18if [ "$COMMAND" = "db-relation-departed" ]; then
52 juju-log "Command not recognized"19 # First remove the address that just departed the relation, then remove the
53 ;;20 # trailing comma from the list, if one exists.
54esac21 sed -i -e "s|\(cassandra_hosts = .*\)'$address'[, ]*|\1|" \
5522 -e "s|, ]|]|" $LOCAL_CONFIG_PATH
56if [ -n "$cassandrahost" ] && [ -n "$rabbithost" ]; then23
57 juju-log "Restarting all retracers"24elif [ "$COMMAND" = "db-relation-joined" ]; then
58 for job in `(cd /etc/init; ls retracer*.conf)`; do 25 p="$LOCAL_CONFIG_PATH"
59 stop ${job%.conf} || true26
60 start ${job%.conf}27 if ! grep -qs 'cassandra_hosts =' $p; then
61 done28 # We do not have a cassandra_hosts variable. Set one with a new list.
62fi29 echo "cassandra_hosts = ['$address']" >> $p
30
31 elif grep -qs "cassandra_hosts =.*']" $p; then
32 # We already have at least one host. Put the new host on the end of the
33 # list.
34 sed -i "s|\(cassandra_hosts.*\)]|\1, '$address']|" $p
35
36 elif grep -qs "cassandra_hosts =.*\[[ *]*\]" $p; then
37 # We have no hosts. Replace the entire line with a new single-element
38 # list.
39 sed -i "s|cassandra_hosts =.*|cassandra_hosts = ['$address']|" $p
40 fi
41
42 if "$(dirname $0)/create-keyspace" "$address"; then
43 OOPS_KEYSPACE=crashdb OOPS_HOST="$address" python \
44 /usr/share/pyshared/oopsrepository/schema.py
45 PYTHONPATH=$LOCAL_CONFIG_LOCATION:$CODE_LOCATION python \
46 $CODE_LOCATION/daisy/schema.py
47 fi
48
49elif [ "$COMMAND" = "db-relation-broken" ]; then
50 sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" $LOCAL_CONFIG_PATH
51fi
52
53# Restart the retracer, since we've changed its configuration.
54retracer_restart
55
56exit 0
6357
=== modified file 'hooks/common'
--- hooks/common 2012-10-10 09:38:57 +0000
+++ hooks/common 2013-02-22 17:21:30 +0000
@@ -1,13 +1,62 @@
1#!/bin/sh1#!/bin/sh
22
3config=/var/retracer/daisy/local_config.py3BASEDIR="$(config-get basedir)"
4INSTANCE_TYPE="$(config-get instance_type)"
5USER_CODE_OWNER=$(config-get user_code_owner)
6GROUP_CODE_OWNER=$(config-get group_code_owner)
7USER_CODE_RUNNER=$(config-get user_code_runner)
8GROUP_CODE_RUNNER=$(config-get group_code_runner)
9ARCHITECTURES="$(config-get daisy-retracer-architectures)"
10DEPLOY_ROOT="/srv/$BASEDIR/$INSTANCE_TYPE"
11CODE_LOCATION="$DEPLOY_ROOT/daisy"
12LOCAL_CONFIG_LOCATION="$DEPLOY_ROOT/local_config"
13LOCAL_CONFIG_PATH="$LOCAL_CONFIG_LOCATION/local_config.py"
14LOG_DIR="/srv/$BASEDIR/$INSTANCE_TYPE-logs"
15APPORT_LOCATION="$DEPLOY_ROOT/apport"
16CACHE_DIR="$DEPLOY_ROOT/cache"
417
5save_setting () {18save_setting () {
6 key="$1"19 key="$1"
7 value="$2"20 value="$2"
8 if ! grep -qs "$key" $config; then21 if ! grep -qs "$key" $LOCAL_CONFIG_PATH; then
9 echo "$key = '$value'" >> $config22 echo "$key = '$value'" >> $LOCAL_CONFIG_PATH
10 else23 else
11 sed -i "s,$key = .*,$key = '$value'," $config24 sed -i "s,$key = .*,$key = '$value'," $LOCAL_CONFIG_PATH
12 fi25 fi
13}26}
27
28add_user () {
29 local user="$1"
30 local group="$2"
31 id $user 2>/dev/null || adduser --quiet --system --disabled-password --ingroup $group $user
32}
33
34add_group () {
35 local group="$1"
36 getent group | grep -qs "^$group:" || addgroup --quiet "$group"
37}
38
39retracer_restart () {
40 # stop all retracers
41 juju-log "Stopping all retracers"
42 for job in `(cd /etc/init; ls retracer*.conf)`; do
43 stop ${job%.conf} || true
44 rm /etc/init/$job
45 done
46
47 # create upstart jobs for configured architectures, and start them
48 for arch in $ARCHITECTURES; do
49 juju-log "Creating upstart job for $arch retracer"
50 cat > /etc/init/retracer-$arch.conf << EOF
51description "error tracker retracer for $arch"
52env PYTHONPATH=$LOCAL_CONFIG_LOCATION:$CODE_LOCATION:$APPORT_LOCATION:$DEPLOY_ROOT
53export PYTHONPATH
54env PATH=$APPORT_LOCATION/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
55export PATH
56exec $CODE_LOCATION/daisy/retracer.py --config-dir $CODE_LOCATION/retracer/config --sandbox-dir $CACHE_DIR --output $LOG_DIR/retracer-$arch.log --architecture $arch
57EOF
58 juju-log "Starting $arch retracer"
59 start retracer-$arch
60
61 done
62}
1463
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2012-12-12 15:11:24 +0000
+++ hooks/config-changed 2013-02-22 17:21:30 +0000
@@ -1,20 +1,27 @@
1#!/bin/sh1#!/bin/sh -eux
2set -eu
32
4. $(dirname $0)/common3. $(dirname $0)/common
54
6# stop all retracers
7juju-log "Stopping all retracers"
8for job in `(cd /etc/init; ls retracer*.conf)`; do
9 stop ${job%.conf} || true
10 rm /etc/init/$job
11done
12
13juju-log "Updating configuration settings"5juju-log "Updating configuration settings"
6
7swift_bucket="$(config-get daisy-retracer-swift-bucket)"
8os_auth_url="$(config-get daisy-retracer-openstack-auth-url)"
9os_username="$(config-get daisy-retracer-openstack-username)"
10os_password="$(config-get daisy-retracer-openstack-password)"
11os_tenant="$(config-get daisy-retracer-openstack-tenant)"
12os_region="$(config-get daisy-retracer-openstack-region)"
13[ -n "$swift_bucket" ] && save_setting swift_bucket "$swift_bucket"
14[ -n "$os_auth_url" ] && save_setting os_auth_url "$os_auth_url"
15[ -n "$os_username" ] && save_setting os_username "$os_username"
16[ -n "$os_password" ] && save_setting os_password "$os_password"
17[ -n "$os_tenant" ] && save_setting os_tenant_name "$os_tenant"
18[ -n "$os_region" ] && save_setting os_region_name "$os_region"
19
14aws_secret_key="$(config-get daisy-retracer-aws-secret-key)"20aws_secret_key="$(config-get daisy-retracer-aws-secret-key)"
15aws_access_key="$(config-get daisy-retracer-aws-access-key)"21aws_access_key="$(config-get daisy-retracer-aws-access-key)"
16ec2_host="$(config-get daisy-retracer-ec2-host)"22ec2_host="$(config-get daisy-retracer-s3-host)"
17ec2_bucket="$(config-get daisy-retracer-ec2-bucket)"23ec2_bucket="$(config-get daisy-retracer-s3-bucket)"
24cassandra_host="$(config-get daisy-retracer-cassandra-host)"
18architectures="$(config-get daisy-retracer-architectures)"25architectures="$(config-get daisy-retracer-architectures)"
1926
20[ -n "$aws_secret_key" ] && save_setting aws_secret_key "$aws_secret_key"27[ -n "$aws_secret_key" ] && save_setting aws_secret_key "$aws_secret_key"
@@ -22,10 +29,11 @@
22[ -n "$ec2_host" ] && save_setting ec2_host "$ec2_host"29[ -n "$ec2_host" ] && save_setting ec2_host "$ec2_host"
23[ -n "$ec2_bucket" ] && save_setting ec2_bucket "$ec2_bucket"30[ -n "$ec2_bucket" ] && save_setting ec2_bucket "$ec2_bucket"
2431
25# create upstart jobs for configured architectures, and start them32# If the user has set daisy-cassandra-host to null, set cassandra_hosts back to
26for arch in $architectures; do33# an empty list.
27 juju-log "Creating upstart job for $arch retracer"34[ -n "$cassandra_host" ] && save_cassandra "$cassandra_host" #|| \
28 sed "s/@ARCH@/$arch/g" hooks/retracer.conf > /etc/init/retracer-$arch.conf35 #sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" $LOCAL_CONFIG_PATH
29 juju-log "Starting $arch retracer"36
30 start retracer-$arch37retracer_restart
31done38
39exit 0
3240
=== added symlink 'hooks/db-relation-broken'
=== target is u'cassandra'
=== removed symlink 'hooks/db-relation-changed'
=== target was u'relation-changed'
=== added symlink 'hooks/db-relation-departed'
=== target is u'cassandra'
=== added symlink 'hooks/db-relation-joined'
=== target is u'cassandra'
=== modified file 'hooks/install'
--- hooks/install 2012-12-12 15:11:24 +0000
+++ hooks/install 2013-02-22 17:21:30 +0000
@@ -1,37 +1,56 @@
1#!/bin/sh1#!/bin/sh
2set -e2set -eux
33
4mkdir -p /var/retracer/cache4. hooks/common
55
6# TODO: move remaining packages over to daisy-seeds PPA6add-apt-repository "$(config-get repository)"
7add-apt-repository ppa:ev/whoopsie-daisy
8add-apt-repository ppa:daisy-pluckers/daisy-seeds
9apt-get update7apt-get update
10# debootstrap is for building the chroot8apt-get install -y retracer-dependencies
11apt-get install -y retracer-dependencies debootstrap9
1210# Create groups
13# get latest release of Apport11add_group "$GROUP_CODE_OWNER"
14if [ -d /var/retracer/apport ]; then12add_group "$GROUP_CODE_RUNNER"
15 cd /var/retracer/apport13
16 bzr pull14# Create users
17else15add_user "$USER_CODE_OWNER" "$GROUP_CODE_OWNER"
18 bzr branch lp:apport /var/retracer/apport16add_user "$USER_CODE_RUNNER" "$GROUP_CODE_RUNNER"
19 cd /var/retracer/apport17
20fi18# Create directories
21LATEST_TAG=`bzr tags | sort -nrk 2 | head -n1 | awk '{print $1}'`19mkdir -p "$CODE_LOCATION" "$LOCAL_CONFIG_LOCATION" "$LOG_DIR" "$APPORT_LOCATION" "$CACHE_DIR"
22bzr uncommit --force -r tag:$LATEST_TAG20
23bzr revert --no-backup21# Unpack tarred Daisy code
24bzr clean-tree --ignored --unknown --force22charm_dir="$(pwd)"
25# set up the apt/dpkg Apport packaging backend; setup.py build would need more23tarball="$charm_dir/files/daisy.tgz"
26# dependencies24
27rm -f apport/packaging_impl.py25if [ -f "$tarball" ]; then
28ln -s ../backends/packaging-apt-dpkg.py apport/packaging_impl.py26 tar -C "$CODE_LOCATION" -xvf "$tarball"
29cd -27fi
3028
31# Retracer config29if [ ! -e "$LOCAL_CONFIG_PATH" ]; then
32if [ -d /var/retracer/daisy ]; then30 cp "$CODE_LOCATION/daisy/configuration.py" "$LOCAL_CONFIG_PATH"
33 (cd /var/retracer/daisy; bzr pull)31fi
34else32
35 bzr branch lp:~ev/daisy/s3 /var/retracer/daisy33# Unpack tarred Apport snapshot
36 cp /var/retracer/daisy/configuration.py /var/retracer/daisy/local_config.py34apport="$charm_dir/files/apport.tgz"
37fi35
36if [ -f "$apport" ]; then
37 tar -C "$APPORT_LOCATION" -xvf "$apport"
38
39 # set up the apt/dpkg Apport packaging backend; setup.py build would need more
40 # dependencies
41 cd "$APPORT_LOCATION"
42 rm -f apport/packaging_impl.py
43 ln -s ../backends/packaging-apt-dpkg.py apport/packaging_impl.py
44 cd -
45fi
46
47# Reset the Cassandra hosts setting. This may have been established by a
48# previous charm, but its contents are now invalid until the config-changed or
49# db-relation-* hooks fires. Its default value of 127.0.0.1 would persist
50# across db-relation-joined and db-relation-departed calls if left set.
51sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" "$LOCAL_CONFIG_PATH"
52
53chown -R $USER_CODE_OWNER:$USER_CODE_RUNNER "/srv/$BASEDIR"
54chown -R $USER_CODE_RUNNER:$GROUP_CODE_RUNNER "$CACHE_DIR"
55
56exit 0
3857
=== removed symlink 'hooks/nfs-relation-changed'
=== target was u'relation-changed'
=== removed file 'hooks/retracer.conf'
--- hooks/retracer.conf 2012-12-12 15:11:24 +0000
+++ hooks/retracer.conf 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
1description "error tracker retracer for @ARCH@"
2
3# Use upstart because James prefers it over supervisord. jjo had a reason for
4# using supervisord - touch base.
5env PYTHONPATH=/var/retracer/daisy:/var/retracer/apport:/var/retracer
6export PYTHONPATH
7env PATH=/var/retracer/apport/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
8export PATH
9exec /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@
100
=== modified file 'revision'
--- revision 2012-12-13 10:14:41 +0000
+++ revision 2013-02-22 17:21:30 +0000
@@ -1,1 +1,1 @@
154159

Subscribers

People subscribed via source and target branches

to all changes: