Merge lp:~gnuoy/charms/precise/errors/add-upgrade-charm into lp:~daisy-pluckers/charms/precise/errors/trunk

Proposed by Liam Young on 2013-05-03
Status: Merged
Merged at revision: 17
Proposed branch: lp:~gnuoy/charms/precise/errors/add-upgrade-charm
Merge into: lp:~daisy-pluckers/charms/precise/errors/trunk
Diff against target: 185 lines (+102/-10)
8 files modified
config.yaml (+19/-0)
hooks/common (+37/-0)
hooks/install (+2/-10)
hooks/nrpe-external-master-relation-changed (+16/-0)
hooks/upgrade-charm (+8/-0)
metadata.yaml (+4/-0)
templates/nrpe_cmd_file.tmpl (+6/-0)
templates/nrpe_service_file.tmpl (+10/-0)
To merge this branch: bzr merge lp:~gnuoy/charms/precise/errors/add-upgrade-charm
Reviewer Review Type Date Requested Status
Evan (community) 2013-05-03 Approve on 2013-05-03
Review via email: mp+162327@code.launchpad.net
To post a comment you must log in.
18. By Liam Young on 2013-05-03

Actually include the upgrade-charm hook

19. By Liam Young on 2013-05-03

Add nrpe hooks and config

20. By Liam Young on 2013-05-03

New hooks need to be executable

21. By Liam Young on 2013-05-03

nrpe hook also needed +x

Evan (ev) wrote :

This looks good. The instructions for creating release tarballs removes the .bzr directory, so we'll have to retain them moving forward, given deploy_code().

review: Approve

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 2013-05-02 22:46:21 +0000
3+++ config.yaml 2013-05-03 14:20:30 +0000
4@@ -43,6 +43,16 @@
5 default: ''
6 description: |
7 The Cassandra RPC password. Leave blank if one is not needed.
8+ daisy_code_dirs:
9+ type: int
10+ default: 3
11+ description: |
12+ How many old copies of daisy code to retain (candidates for backouts)
13+ error_code_dirs:
14+ type: int
15+ default: 3
16+ description: |
17+ How many old copies of error code to retain (candidates for backouts)
18 credentials-database-name:
19 type: string
20 default: 'credentials_cache'
21@@ -68,3 +78,12 @@
22 type: string
23 default: ''
24 description: OAuth secret for talking to Launchpad.net.
25+ nrpe_url_check_params:
26+ default: "-e ' 200 OK' -u / -s 'We collect hundreds of thousands'"
27+ type: string
28+ description: The parameters to use for the check against gunicorn
29+ region:
30+ default: "prodstack"
31+ type: string
32+ description: Region deploying to. Used by nrpe to define servicegroup
33+
34
35=== modified file 'hooks/common'
36--- hooks/common 2013-05-02 22:46:21 +0000
37+++ hooks/common 2013-05-03 14:20:30 +0000
38@@ -18,6 +18,10 @@
39 ERRORS_STATIC_URL="$(config-get errors_static_url)"
40 LP_OAUTH_TOKEN="$(config-get lp_oauth_token)"
41 LP_OAUTH_SECRET="$(config-get lp_oauth_secret)"
42+DAISY_CODE_DIRS="$(config-get daisy_code_dirs)"
43+ERROR_CODE_DIRS="$(config-get error_code_dirs)"
44+REGION="$(config-get region)"
45+NRPE_URL_CHECK_PARAMS="$(config-get nrpe_url_check_params)"
46
47 save_setting () {
48 key="$1"
49@@ -55,3 +59,36 @@
50 relation-set -r $relid wsgi_timestamp=$(date +%s)
51 done
52 }
53+
54+deploy_code () {
55+ local tarball="$1"
56+ local codedir="$2"
57+ local codedir_count="$3"
58+ local codename=$(basename "$codedir")
59+ local coderoot=$(dirname "$codedir")
60+ local tmpdir=$(mktemp -d --tmpdir="${coderoot}")
61+ tar -C ${tmpdir} -xf ${tarball}
62+ local coderevno=$(bzr revno ${tmpdir})
63+ if [[ -d "${coderoot}/${codename}-${coderevno}" ]]; then
64+ juju-log "${coderevno} of ${codename} already deployed"
65+ rm -rf ${tmpdir}
66+ else
67+ juju-log "Deploying ${coderevno} of ${codename}"
68+ chown -R $USER_CODE_OWNER:$USER_CODE_RUNNER "${tmpdir}"
69+ mv "${tmpdir}" "${coderoot}/${codename}-${coderevno}"
70+ [ -d "${coderoot}/${codename}" ] && rm -rf "${coderoot}/${codename}"
71+ ln -s "${coderoot}/${codename}-${coderevno}" "${coderoot}/${codename}"
72+ remove_old_codedirs $codedir_count "${coderoot}/${codename}-*"
73+ fi
74+}
75+
76+remove_old_codedirs () {
77+ local codedir_count="$1"
78+ local codedir_regex="$2"
79+ local current_code_dirs=$(ls -d ${codedir_regex} | wc -l)
80+ if [[ $current_code_dirs -gt $codedir_count ]]; then
81+ juju-log "More than $codedir_count found, deleting:"
82+ juju-log "$(ls -td ${codedir_regex} | tail -n +$(($codedir_count+1)))"
83+ ls -1rd ${codedir_regex} | tail -n +$(($codedir_count+1)) | xargs rm -rf
84+ fi
85+}
86
87=== modified file 'hooks/config-changed' (properties changed: -x to +x)
88=== modified file 'hooks/install'
89--- hooks/install 2013-05-01 15:17:25 +0000
90+++ hooks/install 2013-05-03 14:20:30 +0000
91@@ -33,16 +33,8 @@
92
93 # Unpack tarred Errors code
94 charm_dir="$(pwd)"
95-tarball="$charm_dir/files/errors.tgz"
96-
97-if [ -f "$tarball" ]; then
98- tar -C "$CODE_LOCATION" -xvf "$tarball"
99-fi
100-
101-daisy="$charm_dir/files/daisy.tgz"
102-if [ -f "$daisy" ]; then
103- tar -C "$DAISY_LOCATION" -xvf "$daisy"
104-fi
105+deploy_code "$charm_dir/files/errors.tgz" $CODE_LOCATION $ERROR_CODE_DIRS
106+deploy_code "$charm_dir/files/daisy.tgz" $DAISY_LOCATION $DAISY_CODE_DIRS
107
108 if [ ! -e "$LOCAL_CONFIG_PATH" ]; then
109 cp "$DAISY_LOCATION/daisy/configuration.py" "$LOCAL_CONFIG_PATH"
110
111=== added file 'hooks/nrpe-external-master-relation-changed'
112--- hooks/nrpe-external-master-relation-changed 1970-01-01 00:00:00 +0000
113+++ hooks/nrpe-external-master-relation-changed 2013-05-03 14:20:30 +0000
114@@ -0,0 +1,16 @@
115+#!/bin/bash
116+set -eux
117+. hooks/common
118+export NAGIOS_HOSTNAME="ue-${REGION}-et-${JUJU_UNIT_NAME//\//-}"
119+
120+export INSTANCE_TYPE
121+export NAGIOS_SERVICEGROUP="ue-${REGION}-et"
122+export PROJECT="UE"
123+
124+export SERVICE_DESCRIPTION="Error tracker app server"
125+export NRPE_CMD_NAME="check_ue_error_app_${INSTANCE_TYPE}"
126+export NRPE_CMD="/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -p ${LISTEN_PORT} ${NRPE_URL_CHECK_PARAMS}"
127+cheetah fill --env -p templates/nrpe_cmd_file.tmpl > /etc/nagios/nrpe.d/${NRPE_CMD_NAME}.cfg
128+cheetah fill --env -p templates/nrpe_service_file.tmpl > /var/lib/nagios/export/service__${NAGIOS_HOSTNAME}_${NRPE_CMD_NAME}.cfg
129+
130+/etc/init.d/nagios-nrpe-server reload
131
132=== added file 'hooks/upgrade-charm'
133--- hooks/upgrade-charm 1970-01-01 00:00:00 +0000
134+++ hooks/upgrade-charm 2013-05-03 14:20:30 +0000
135@@ -0,0 +1,8 @@
136+#!/bin/bash
137+set -eux
138+
139+. hooks/common
140+charm_dir="$(pwd)"
141+deploy_code "$charm_dir/files/errors.tgz" $CODE_LOCATION $ERROR_CODE_DIRS
142+deploy_code "$charm_dir/files/daisy.tgz" $DAISY_LOCATION $DAISY_CODE_DIRS
143+service gunicorn restart
144
145=== modified file 'metadata.yaml'
146--- metadata.yaml 2013-01-09 12:26:52 +0000
147+++ metadata.yaml 2013-05-03 14:20:30 +0000
148@@ -10,6 +10,10 @@
149 scope: container
150 errors:
151 interface: http
152+ nrpe-external-master:
153+ interface: nrpe-external-master
154+ scope: container
155+
156 requires:
157 db:
158 interface: cassandra
159
160=== added directory 'templates'
161=== added file 'templates/nrpe_cmd_file.tmpl'
162--- templates/nrpe_cmd_file.tmpl 1970-01-01 00:00:00 +0000
163+++ templates/nrpe_cmd_file.tmpl 2013-05-03 14:20:30 +0000
164@@ -0,0 +1,6 @@
165+#---------------------------------------------------
166+# This file is Juju managed
167+#---------------------------------------------------
168+# ${PROJECT} ${INSTANCE_TYPE} ${SERVICE_DESCRIPTION}
169+command[${NRPE_CMD_NAME}]=${NRPE_CMD}
170+
171
172=== added file 'templates/nrpe_service_file.tmpl'
173--- templates/nrpe_service_file.tmpl 1970-01-01 00:00:00 +0000
174+++ templates/nrpe_service_file.tmpl 2013-05-03 14:20:30 +0000
175@@ -0,0 +1,10 @@
176+#---------------------------------------------------
177+# This file is Juju managed
178+#---------------------------------------------------
179+define service {
180+ use active-service
181+ host_name ${NAGIOS_HOSTNAME}
182+ service_description ${NAGIOS_HOSTNAME} ${PROJECT} ${INSTANCE_TYPE} ${SERVICE_DESCRIPTION}
183+ check_command check_nrpe!${NRPE_CMD_NAME}
184+ servicegroups ${NAGIOS_SERVICEGROUP},
185+}

Subscribers

People subscribed via source and target branches

to all changes: