Merge lp:~thedac/charms/precise/pgbouncer/nagios-check-fixes into lp:charms/pgbouncer

Proposed by David Ames
Status: Merged
Merged at revision: 59
Proposed branch: lp:~thedac/charms/precise/pgbouncer/nagios-check-fixes
Merge into: lp:charms/pgbouncer
Diff against target: 184 lines (+67/-14)
7 files modified
config.yaml (+6/-0)
hooks/config-changed (+2/-0)
hooks/db-proxy-relation-changed (+2/-2)
hooks/install (+2/-0)
hooks/nrpe-external-master-relation-changed (+36/-11)
revision (+1/-1)
scripts/common (+18/-0)
To merge this branch: bzr merge lp:~thedac/charms/precise/pgbouncer/nagios-check-fixes
Reviewer Review Type Date Requested Status
Dave Cheney (community) lgtm Approve
charmers Pending
Review via email: mp+183250@code.launchpad.net

Description of the change

Setup nagios .pgpass and userlist.txt entry for nagios checks

To post a comment you must log in.
Revision history for this message
Dave Cheney (dave-cheney) :
review: Approve (lgtm)
Revision history for this message
David Ames (thedac) wrote :

Dave,

Any chance you can merge this. Matthew will not have to time to do a review.

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-02-25 05:22:47 +0000
3+++ config.yaml 2013-08-30 18:41:25 +0000
4@@ -149,6 +149,12 @@
5 type: string
6 description: |
7 What service this component forms part of. Used by nrpe.
8+ package_status:
9+ default: "install"
10+ type: string
11+ description: |
12+ The status of service-affecting packages will be set to this value in the dpkg database.
13+ Useful valid values are "install" and "hold".
14 wait_warn:
15 default: 5
16 type: int
17
18=== modified file 'hooks/config-changed'
19--- hooks/config-changed 2012-10-02 08:57:36 +0000
20+++ hooks/config-changed 2013-08-30 18:41:25 +0000
21@@ -11,5 +11,7 @@
22 juju-log "Generating new pgbouncer configuration and init script"
23 update_config
24
25+ensure_package_status "${SERVICE_AFFECTING_PACKAGES}" $(config-get package_status)
26+
27 juju-log "Reloading pgbouncer"
28 /usr/sbin/service pgbouncer reload
29
30=== modified file 'hooks/db-proxy-relation-changed'
31--- hooks/db-proxy-relation-changed 2013-03-22 14:30:59 +0000
32+++ hooks/db-proxy-relation-changed 2013-08-30 18:41:25 +0000
33@@ -113,8 +113,8 @@
34 if [ "$JUJU_RELATION" != "db-proxy" ]; then
35 # If called out of context
36 juju-log "Out of db-proxy relation context, manually setting JUJU vars for db-proxy relation"
37- JUJU_RELATION="db-proxy"
38- export JUJU_RELATION_IDS=$(relation-ids db-proxy)
39+ export JUJU_RELATION="db-proxy"
40+ JUJU_RELATION_IDS=$(relation-ids db-proxy)
41 UPDATED="False"
42 for JUJU_RELATION_ID in $(echo ${JUJU_RELATION_ID}); do
43 export JUJU_REMOTE_UNIT=$(relation-list -r $JUJU_RELATION_ID)
44
45=== modified file 'hooks/install'
46--- hooks/install 2013-01-03 18:15:45 +0000
47+++ hooks/install 2013-08-30 18:41:25 +0000
48@@ -22,6 +22,8 @@
49 juju-log "Installing packages via apt-get"
50 apt-get -y install -- pgbouncer python-cheetah postgresql-client pwgen python-psycopg2
51
52+ensure_package_status "${SERVICE_AFFECTING_PACKAGES}" $(config-get package_status)
53+
54 # Make sure pgbouncer is enabled and set max open files
55 max_open_files=$(config-get max_open_files)
56 cat >/etc/default/pgbouncer << EOF
57
58=== modified file 'hooks/nrpe-external-master-relation-changed'
59--- hooks/nrpe-external-master-relation-changed 2013-02-25 07:15:10 +0000
60+++ hooks/nrpe-external-master-relation-changed 2013-08-30 18:41:25 +0000
61@@ -3,6 +3,9 @@
62 # Copyright 2012 Canonical Ltd. All rights reserved.
63 # Author: Haw Loeung <haw.loeung@canonical.com>
64
65+set -eux # -x for verbose logging to juju debug-log
66+. scripts/common
67+
68 unit_name=${JUJU_UNIT_NAME////-}
69 nagios_hostname="$(config-get nagios_context)-${unit_name}"
70 nagios_logdir='/var/log/nagios'
71@@ -10,29 +13,29 @@
72 nagios_servicegroup=$(config-get nagios_context)
73 address=$(config-get listen_addr)
74 if [ "$address" = "*" ]; then
75- address=$(unit-get private-address)
76+ address=$(unit-get private-address)
77 fi
78
79 nagios_uid=$(getent passwd nagios | awk -F: '{ print $3}')
80 nagios_gid=$(getent passwd nagios | awk -F: '{ print $4}')
81 if [ $? -ne 0 ]; then
82- juju-log "Nagios user not setup, exiting"
83- exit 1
84+ juju-log "Nagios user not setup, exiting"
85+ exit 1
86 fi
87
88 if [ -d /usr/local/lib/nagios/plugins/ ]; then
89- cp $CHARM_DIR/scripts/check-pgbouncer.py $nagios_check_script
90- chmod 755 $nagios_check_script
91+ cp $CHARM_DIR/scripts/check-pgbouncer.py $nagios_check_script
92+ chmod 755 $nagios_check_script
93 fi
94
95 if [ ! -d $nagios_logdir ]; then
96- mkdir $nagios_logdir
97- chown nagios:nagios $nagios_logdir
98+ mkdir $nagios_logdir
99+ chown nagios:nagios $nagios_logdir
100 fi
101
102 # Remove existing checks to start clean
103 for FILE in /var/lib/nagios/export/*check_pgbouncer*.cfg; do
104- rm -f $FILE
105+ rm -f $FILE
106 done
107
108 # Export Juju configs and relations.
109@@ -63,10 +66,32 @@
110 # Clean up
111 rm -f $juju_configs
112
113+# Create nagios user in pgbouncer
114+nagios_home=$(getent passwd nagios | awk -F: '{ print $6 }')
115+if [ ! -f ${nagios_home}/.pgpass ] || [ ! -f /var/lib/juju/nagios.password ]; then
116+ password=$(pwgen -s 16)
117+ nagios_home=$(getent passwd nagios | awk -F: '{ print $6 }')
118+ if [ -d $nagios_home ]; then
119+ echo "*:*:*:nagios:${password}" > ${nagios_home}/.pgpass
120+ chown nagios:nagios ${nagios_home}/.pgpass
121+ chmod 600 ${nagios_home}/.pgpass
122+ else
123+ juju-log "No home directory for nagios"
124+ exit 1
125+ fi
126+ if [ -d /var/lib/juju/ ]; then
127+ echo "${password}" > /var/lib/juju/nagios.password
128+ update_config
129+ else
130+ juju-log "No /var/lib/juju directory"
131+ exit 1
132+ fi
133+fi
134+
135 # Reload NRPE
136 if [ -x /etc/init.d/nagios-nrpe-server ]; then
137- service nagios-nrpe-server reload
138+ service nagios-nrpe-server reload
139 else
140- juju-log "Is NRPE installed?"
141- exit 1
142+ juju-log "Is NRPE installed?"
143+ exit 1
144 fi
145
146=== modified file 'revision'
147--- revision 2013-02-25 05:23:43 +0000
148+++ revision 2013-08-30 18:41:25 +0000
149@@ -1,1 +1,1 @@
150-1
151+2
152
153=== modified file 'scripts/common'
154--- scripts/common 2013-02-27 03:43:44 +0000
155+++ scripts/common 2013-08-30 18:41:25 +0000
156@@ -7,6 +7,8 @@
157
158 set -eux # -x for verbose logging to juju debug-log
159
160+SERVICE_AFFECTING_PACKAGES="pgbouncer"
161+
162 update_config()
163 {
164 pgbouncer_userlist=/etc/pgbouncer/userlist.txt
165@@ -50,3 +52,19 @@
166 juju-log "reloading pgbouncer"
167 service pgbouncer reload || exit 1
168 }
169+
170+ensure_package_status()
171+{
172+ packages="$1" ; shift
173+ status="$1" ; shift
174+
175+ case $status in
176+ install|hold)
177+ for package in ${packages}; do
178+ echo ${package} ${status}
179+ done | dpkg --set-selections
180+ ;;
181+ *)
182+ ;;
183+ esac
184+}

Subscribers

People subscribed via source and target branches

to all changes: