Merge lp:~abentley/charms/precise/charmworld/special-users into lp:~juju-jitsu/charms/precise/charmworld/trunk

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 39
Proposed branch: lp:~abentley/charms/precise/charmworld/special-users
Merge into: lp:~juju-jitsu/charms/precise/charmworld/trunk
Diff against target: 254 lines (+64/-34)
12 files modified
common (+4/-1)
files/nrpe-external-master/check_ingest.sh (+1/-1)
hooks/config-changed (+3/-3)
hooks/database-relation-changed (+5/-4)
hooks/install (+19/-4)
hooks/start (+2/-2)
hooks/stop (+7/-4)
hooks/upgrade-charm (+8/-8)
nginx/http (+1/-1)
production_overrides.ini (+1/-1)
revision (+1/-1)
scripts/gen_deploymgr.py (+12/-4)
To merge this branch: bzr merge lp:~abentley/charms/precise/charmworld/special-users
Reviewer Review Type Date Requested Status
Juju-Jitsu Hackers Pending
Review via email: mp+147228@code.launchpad.net

Description of the change

Install as webops_deploy, run as charmworld

Update hooks to install files as webops_deploy, but to run charmworld as the
charmworld user. Log files and branches are written to ~charmworld/var.
nginx is updated to use the new location for static files.

https://codereview.appspot.com/7311060/

To post a comment you must log in.
Revision history for this message
Richard Harding (rharding) wrote :

lgtm just wanted to check on using the new common variables in more
places to prevent too many occurances to change later if needed.

https://codereview.appspot.com/7311060/diff/1/files/nrpe-external-master/check_ingest.sh
File files/nrpe-external-master/check_ingest.sh (right):

https://codereview.appspot.com/7311060/diff/1/files/nrpe-external-master/check_ingest.sh#newcode2
files/nrpe-external-master/check_ingest.sh:2: if [ -f
/home/charmworld/var/ingest-errors ]; then
Should this be set to use the charmworld_home var defined in common?

https://codereview.appspot.com/7311060/diff/1/hooks/config-changed
File hooks/config-changed (right):

https://codereview.appspot.com/7311060/diff/1/hooks/config-changed#newcode82
hooks/config-changed:82: */$interval * * * * charmworld
HOME=/home/charmworld LOGDIR=$log_dir INI=$CONFIG_FILE
~webops_deploy/run-write-errors $log_dir/ingest-errors
$project_dir/scripts/ingest
again should this use the variable defined for charmworkd_home like the
log_dir variable?

https://codereview.appspot.com/7311060/diff/1/hooks/config-changed#newcode83
hooks/config-changed:83: @daily charmworld HOME=/home/webops_deploy
INI=$project_dir/production.ini $project_dir/bin/python
$project_dir/charmworld/jobs/cstat.py
and webops_home here.

https://codereview.appspot.com/7311060/

Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you Aaron, lgtm.

I don't have any comment about the mechanical changes in in the diff. I
was surprised to see the "-R" option following the positional args to
chown in a few places (they pre-exist your change). I was surprised. I
used to reading the options before what might be a long of positional
args.

https://codereview.appspot.com/7311060/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common'
2--- common 2013-01-29 15:32:47 +0000
3+++ common 2013-02-07 21:17:21 +0000
4@@ -1,4 +1,7 @@
5-project_dir="/home/ubuntu/charmworld"
6+webops_home="/home/webops_deploy"
7+charmworld_home="/home/charmworld"
8+log_dir="$charmworld_home/var"
9+project_dir="$webops_home/charmworld"
10 CONFIG_FILE="$project_dir/production.ini"
11 configure(){
12 ./write_config.py $project_dir/default.ini production_overrides.ini\
13
14=== modified file 'files/nrpe-external-master/check_ingest.sh'
15--- files/nrpe-external-master/check_ingest.sh 2013-01-31 20:03:15 +0000
16+++ files/nrpe-external-master/check_ingest.sh 2013-02-07 21:17:21 +0000
17@@ -1,5 +1,5 @@
18 #!/bin/sh
19-if [ -f /home/ubuntu/var/ingest-errors ]; then
20+if [ -f /home/charmworld/var/ingest-errors ]; then
21 echo Charmworld ingest failing
22 exit 1
23 fi
24
25=== modified file 'hooks/config-changed'
26--- hooks/config-changed 2013-01-31 21:28:17 +0000
27+++ hooks/config-changed 2013-02-07 21:17:21 +0000
28@@ -36,7 +36,7 @@
29 cd $old_dir
30 configure
31 cd $project_dir
32- chown ubuntu.ubuntu . -R
33+ chown webops_deploy.webops_deploy . -R
34 if grep -E 'mongo.host = .+' $CONFIG_FILE; then
35 INI=$CONFIG_FILE bin/migrations upgrade
36 cd $old_dir
37@@ -79,8 +79,8 @@
38 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
39 $mailto
40
41-*/$interval * * * * ubuntu HOME=/home/ubuntu INI=$CONFIG_FILE ~ubuntu/run-write-errors /home/ubuntu/var/ingest-errors $project_dir/scripts/ingest
42-@daily ubuntu HOME=/home/ubuntu INI=$project_dir/production.ini $project_dir/bin/python $project_dir/charmworld/jobs/cstat.py
43+*/$interval * * * * charmworld HOME=/home/charmworld LOGDIR=$log_dir INI=$CONFIG_FILE ~webops_deploy/run-write-errors $log_dir/ingest-errors $project_dir/scripts/ingest
44+@daily charmworld HOME=/home/webops_deploy INI=$project_dir/production.ini $project_dir/bin/python $project_dir/charmworld/jobs/cstat.py
45
46 EOF
47
48
49=== modified file 'hooks/database-relation-changed'
50--- hooks/database-relation-changed 2013-01-28 21:23:17 +0000
51+++ hooks/database-relation-changed 2013-02-07 21:17:21 +0000
52@@ -4,7 +4,7 @@
53 set -x
54
55 DB_HOST=`relation-get private-address`
56-HOME=/home/ubuntu
57+HOME=$webops_home
58
59 if [ -z "$DB_HOST" ]; then
60 juju-log "Waiting for handshake from mongodb"
61@@ -20,12 +20,13 @@
62
63 configure $DB_HOST $DB_PORT
64
65-INI=$CONFIG_FILE $project_dir/bin/migrations upgrade --init
66+su charmworld -c "export INI=$CONFIG_FILE; $project_dir/bin/migrations upgrade --init"
67
68 juju-log "Hey, we're ingesting over here. This WILL take a while."
69 # Perform an initial ingest
70-su ubuntu -c "INI=$CONFIG_FILE HOME=/home/ubuntu/ \
71- PYTHON_BIN=$project_dir/bin/python /home/ubuntu/charmworld/scripts/ingest"
72+su charmworld -c "INI=$CONFIG_FILE HOME=$charmworld_home \
73+ LOGDIR=$log_dir PYTHON_BIN=$project_dir/bin/python \
74+ $project_dir/scripts/ingest"
75
76 open-port 80
77
78
79=== modified file 'hooks/install'
80--- hooks/install 2013-01-31 21:28:17 +0000
81+++ hooks/install 2013-02-07 21:17:21 +0000
82@@ -1,5 +1,7 @@
83 #!/bin/bash
84-set -eux
85+set -eu
86+source common
87+set -x
88
89 # This PPA is no longer required. Remove for all running charms upgrading to
90 # current status. #rev 15
91@@ -15,7 +17,20 @@
92 echo '/(.*)@charmworld-instance/ charmworld-instance+${1}@canonical.com' > /etc/postfix/canonical
93 postmap /etc/postfix/canonical
94 postfix reload
95-mkdir -p ~ubuntu/var/charms
96-chown -R ubuntu.ubuntu ~ubuntu/var
97-install -o ubuntu -g ubuntu scripts/run-write-errors ~ubuntu
98+ensure_user(){
99+ set +e
100+ useradd --create-home $1
101+ result=$?
102+ if [ $result -ne 0 -a $result -ne 9 ]; then
103+ exit $result
104+ fi
105+ set -e
106+}
107+ensure_user webops_deploy
108+ensure_user charmworld
109+INSTALL="install -o webops_deploy -g webops_deploy"
110+# both var and var/charms need to be writable by charmworld.
111+install -o charmworld -g charmworld -m 0755 -d $charmworld_home/var
112+install -o charmworld -g charmworld -m 0755 -d $charmworld_home/var/charms
113+$INSTALL scripts/run-write-errors $webops_home
114 python scripts/gen_deploymgr.py
115
116=== modified file 'hooks/start'
117--- hooks/start 2013-01-16 16:05:49 +0000
118+++ hooks/start 2013-02-07 21:17:21 +0000
119@@ -5,7 +5,7 @@
120
121 if [ -f "$project_dir/scripts/run" ]; then
122 cd $project_dir
123- HOME=/home/ubuntu INI=$CONFIG_FILE scripts/run
124+ su charmworld -c "HOME=$charmworld_home PROJECT_DIR=$project_dir INI=$CONFIG_FILE scripts/run"
125 # This will restart Nginx which we'll probably want to do
126- HOME=/home/ubuntu scripts/clear-cache
127+ scripts/clear-cache
128 fi
129
130=== modified file 'hooks/stop'
131--- hooks/stop 2013-01-08 20:40:10 +0000
132+++ hooks/stop 2013-02-07 21:17:21 +0000
133@@ -1,7 +1,10 @@
134 #!/bin/bash
135-set -eux
136+set -eu
137+source common
138+set -x
139
140-if [ -f "/home/ubuntu/charmworld/scripts/stop" ]; then
141- cd /home/ubuntu/charmworld
142- HOME=/home/ubuntu scripts/stop
143+stop_script="$project_dir/scripts/stop"
144+if [ -f "$stop_script" ]; then
145+ cd $project_dir
146+ su charmworld -c "HOME=$charmworld_home PROJECT_DIR=$project_dir $stop_script"
147 fi
148
149=== modified file 'hooks/upgrade-charm'
150--- hooks/upgrade-charm 2013-01-30 20:34:57 +0000
151+++ hooks/upgrade-charm 2013-02-07 21:17:21 +0000
152@@ -1,15 +1,15 @@
153 #!/bin/bash
154 set -eux
155
156-HOME=/home/ubuntu
157-
158 hooks/stop || true
159 hooks/install
160-if [ -d $HOME/.launchpadlib ]; then
161- chown -R ubuntu.ubuntu $HOME/.launchpadlib;
162-fi
163+maybe_rm(){
164+ if [ -d $1 ]; then
165+ rm $1 -R
166+ fi
167+}
168+maybe_rm ~ubuntu/charmworld
169+maybe_rm ~ubuntu/var
170 hooks/config-changed
171 hooks/restart
172-if [ -f $HOME/shhh.py ]; then
173- rm $HOME/shhh.py
174-fi
175+maybe_rm ~ubuntu/shhh.py
176
177=== modified file 'nginx/http'
178--- nginx/http 2013-01-21 20:38:02 +0000
179+++ nginx/http 2013-02-07 21:17:21 +0000
180@@ -40,7 +40,7 @@
181 location /static {
182 gzip on;
183 expires 48h;
184- alias /home/ubuntu/charmworld/charmworld/static;
185+ alias /home/webops_deploy/charmworld/charmworld/static;
186 }
187
188 location / {
189
190=== modified file 'production_overrides.ini'
191--- production_overrides.ini 2013-01-28 21:23:17 +0000
192+++ production_overrides.ini 2013-02-07 21:17:21 +0000
193@@ -32,7 +32,7 @@
194
195 [handler_filelog]
196 class = FileHandler
197-args = ('/home/ubuntu/var/app.log', 'a')
198+args = ('/home/charmworld/var/app.log', 'a')
199 level = INFO
200 formatter = generic
201
202
203=== modified file 'revision'
204--- revision 2013-02-04 17:13:16 +0000
205+++ revision 2013-02-07 21:17:21 +0000
206@@ -1,1 +1,1 @@
207-20
208+21
209
210=== modified file 'scripts/gen_deploymgr.py'
211--- scripts/gen_deploymgr.py 2013-01-31 20:38:24 +0000
212+++ scripts/gen_deploymgr.py 2013-02-07 21:17:21 +0000
213@@ -1,9 +1,15 @@
214 #!/usr/bin/env python
215-from os import chmod
216-from os import makedirs
217+from os import (
218+ chmod,
219+ fchmod,
220+ chown,
221+ fchown,
222+ makedirs,
223+ )
224 from os.path import abspath
225 from os.path import dirname
226 from os.path import exists
227+from pwd import getpwnam
228 from string import Template
229
230
231@@ -18,6 +24,7 @@
232 if not exists(directory):
233 makedirs(directory)
234 chmod(directory, 0755)
235+ chown(directory, WEBOPS_UID, WEBOPS_GID)
236
237
238 def write_deploymgr():
239@@ -26,12 +33,13 @@
240 rendered = template.substitute({
241 'charm_dir': CHARM_DIR
242 })
243-
244 with open(DEPLOYMGR_OUT, 'w') as output:
245+ fchown(output.fileno(), WEBOPS_UID, WEBOPS_GID)
246+ fchmod(output.fileno(), 0755)
247 output.writelines(rendered)
248- chmod(DEPLOYMGR_OUT, 0755)
249
250
251 if __name__ == "__main__":
252+ WEBOPS_UID, WEBOPS_GID = getpwnam('webops_deploy')[2:4]
253 prep_output_path(DEPLOYMGR_OUT)
254 write_deploymgr()

Subscribers

People subscribed via source and target branches

to all changes: