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

Proposed by Liam Young on 2013-05-03
Status: Merged
Merged at revision: 30
Proposed branch: lp:~gnuoy/charms/precise/daisy/add-upgrade-charm
Merge into: lp:~daisy-pluckers/charms/precise/daisy/trunk
Diff against target: 168 lines (+94/-5)
8 files modified
config.yaml (+14/-0)
hooks/common (+36/-0)
hooks/install (+1/-5)
hooks/nrpe-external-master-relation-changed (+16/-0)
hooks/upgrade-charm (+7/-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/daisy/add-upgrade-charm
Reviewer Review Type Date Requested Status
Evan (community) 2013-05-03 Approve on 2013-05-03
Review via email: mp+162328@code.launchpad.net
To post a comment you must log in.
31. By Liam Young on 2013-05-03

Actually include the upgrade-charm hook

32. By Liam Young on 2013-05-03

Add nrpe hooks and config

33. By Liam Young on 2013-05-03

New hooks need to be executable

34. By Liam Young on 2013-05-03

nrpe hook also needed +x

Evan (ev) wrote :

Looks good!

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

Subscribers

People subscribed via source and target branches

to all changes: