Merge lp:~jose/charms/precise/tracks/fixes into lp:charms/tracks

Proposed by José Antonio Rey
Status: Merged
Merged at revision: 5
Proposed branch: lp:~jose/charms/precise/tracks/fixes
Merge into: lp:charms/tracks
Diff against target: 287 lines (+143/-46)
9 files modified
README (+0/-21)
README.md (+40/-0)
config.yaml (+1/-1)
hooks/config-changed (+31/-0)
hooks/db-relation-changed (+27/-13)
hooks/install (+37/-7)
hooks/stop (+3/-4)
hooks/website-relation-joined (+2/-0)
metadata.yaml (+2/-0)
To merge this branch: bzr merge lp:~jose/charms/precise/tracks/fixes
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Cory Johns (community) +1 Approve
Review via email: mp+215987@code.launchpad.net

Description of the change

 * Converted the README to Markdown
 * Added support to change the port number if it's already been configured

To post a comment you must log in.
Revision history for this message
Cory Johns (johnsca) wrote :

Jose,

Thank you very much for your contribution to this charm. Unfortunately, I was unable to deploy the charm, so I was unable to properly test your changes, though the error doesn't seem to be related to your changes here. The error I got was:

    INFO install Errno::ENOENT: No such file or directory - /Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-private_key.pem
    INFO install An error occurred while installing has_many_polymorphs (2.13), and Bundler
    INFO install cannot continue.
    INFO install Make sure that `gem install has_many_polymorphs -v '2.13'` succeeds before
    INFO install bundling.
    ERROR juju.worker.uniter uniter.go:490 hook failed: exit status 5

I tried on two different environments and got the same error. If you were able to deploy the charm, was there anything you did differently to avoid this error?

Regarding your changes, they seem good, though I would suggest that you add indentation for the if blocks in the config-changed and db-relation-changed hooks, to make them more readable.

Again, thank you for this improvement, and if you can assist me getting this deployed, I can test it to give it my +1.

Revision history for this message
Cory Johns (johnsca) :
review: Needs Information
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Moved to "work in progress" pending feedback, once ready for another review please move to "Needs Review"

Revision history for this message
José Antonio Rey (jose) wrote :

Cory,

Googling a bit, this is a problem that has already been reported (see bug #1155358), and looks like some gems that ship with tracks are broken. We will need to figure out if there is some workaround for this first, I'll make sure to take a look into it soon.

Revision history for this message
José Antonio Rey (jose) wrote :

Charm now goes in the right track - fixed the errors and it should be good to go.

lp:~jose/charms/precise/tracks/fixes updated
9. By José Antonio Rey

Fixed some bugs, still need to fix upstart job

10. By José Antonio Rey

Fixed all errors, ready for review

Revision history for this message
Cory Johns (johnsca) wrote :

José,

Thanks so much for these improvements! This charm is so much more robust and secure for these changes!

However, I noticed an issue regarding the port handling: if you set the port to a small number initially, a log message indicating that the port is not allowed is recorded, but the upstart script is still created with the low-numbered port. Further, if you set the port to a high-numbered port and then later change the port number, because the .portnotsupported file doesn't exist, the the port check is skipped entirely and the port is not changed.

I think that the .portnotsupported file check can be removed entirely, and the port check in the install script should be moved down to wrap the creation of the upstart conf, with an else clause to remove the conf if it exists. The existing service will also need to be stopped before the upstart conf is changed or removed and restarted after the new conf is in place (though, there's also the database to consider, so there might need to be a .db-configured marker file or something, that is checked before starting the service from hooks/install).

Additionally, to allow this to work with a reverse proxy, as is the intention, I believe the website-relation-joined hook must be added, but I think it can be a simple boiler-plate hook, such as: http://pastebin.ubuntu.com/7412868/

Lastly, I had a question regarding the db-relation-changed hook: do you know if it matters if rake db:migrate is called multiple times? If it does, then that hook isn't idempotent and needs a check, but since the original hook doesn't have that, maybe it doesn't matter if it's called again.

lp:~jose/charms/precise/tracks/fixes updated
11. By José Antonio Rey

Fixed some bugs

12. By José Antonio Rey

Fixed a problem with ports check

Revision history for this message
José Antonio Rey (jose) wrote :

Hey Cory,

Fixed as discussed on IRC.

Thank you!

lp:~jose/charms/precise/tracks/fixes updated
13. By José Antonio Rey

Fixed redundancy

14. By José Antonio Rey

Fixed problem with brackets and non-executable website-relation-joined hook

15. By José Antonio Rey

Fixed port-changing blocker

Revision history for this message
Cory Johns (johnsca) wrote :

One small issue remaining: http://pastebin.ubuntu.com/7422057/

Looks like [[ "$PORT" < 1025 ]] should be [[ "$PORT" -lt 1025 ]]

lp:~jose/charms/precise/tracks/fixes updated
16. By José Antonio Rey

Changed < for -lt

Revision history for this message
Cory Johns (johnsca) wrote :

José,

Thank you very much for working with me to get this charm fixed, since it turned out to be broken upstream. With your changes, not only does the charm work again, but it is more secure (no longer running as root) and robust (using upstart, working with reverse proxy charms, etc). Excellent work!

I definitely give this MP my +1 and it should be merged by a charmer soon.

review: Approve (+1)
Revision history for this message
Charles Butler (lazypower) wrote :

Jose, thanks for the submission!

I've reviewed the associated content and everything seems to be in order. +1 and merging.

Keep up the great work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'README'
2--- README 2013-02-21 03:31:54 +0000
3+++ README 1970-01-01 00:00:00 +0000
4@@ -1,21 +0,0 @@
5-Tracks is a Ruby on Rails based web service that helps you to manage to
6-do lists and get things done (GTD). Tracks is based on David Allen's Get
7-Things Done (TM) methodology.
8-
9-To deploy:
10- juju bootstrap
11- juju deploy tracks
12- juju deploy mysql
13- juju add-relation mysql tracks
14- juju expose tracks
15-
16- Then do a `juju status` to determine the IP of the service,
17- and just open it in your browser. On the initial screen you can
18- create your user, then sign-in and begin using Tracks. This charm
19- offers one configuration option, the port on which to run the web
20- server, default is 80. Tracks uses a built-in webserver, WEBrick.
21-
22-Links:
23-
24-- Homepage: http://getontracks.org/
25-- Code: https://github.com/TracksApp/tracks
26
27=== added file 'README.md'
28--- README.md 1970-01-01 00:00:00 +0000
29+++ README.md 2014-05-12 19:08:21 +0000
30@@ -0,0 +1,40 @@
31+# Overview
32+
33+Tracks is a Ruby on Rails based web service that helps you to manage to do lists
34+and get things done (GTD). Tracks is based on David Allen's Get Things Done (TM)
35+methodology.
36+
37+Please note that this charm uses the brightbox/ruby-ng PPA in order to get a
38+newer version of Ruby.
39+
40+# Usage
41+
42+To deploy:
43+
44+ juju bootstrap
45+ juju deploy tracks
46+ juju deploy mysql
47+ juju add-relation mysql tracks
48+ juju expose tracks
49+
50+Then do a `juju status` to determine the IP of the service, and just open it in
51+your browser. On the initial screen you can create your user, then sign-in and
52+begin using Tracks. It uses a built-in webserver, WEBrick.
53+
54+## Configuration
55+
56+This charm offers one configuration option, the port on which to run the web
57+server, default is 3000. At this point, it can not be ran in a port minor to
58+1025. If you set a port lower or equal to 1024, it will refuse to install
59+until you change it. If you want to use port 80, for example, you can add a
60+reverse proxy server, such as haproxy (also available in Juju).
61+
62+# Known Limitations
63+
64+As mentioned in the configuration part, the charm does not currently allow a
65+port number lower than 1025.
66+
67+# Links
68+
69+- Homepage: <http://getontracks.org/>
70+- Code: <https://github.com/TracksApp/tracks>
71
72=== modified file 'config.yaml'
73--- config.yaml 2012-11-27 22:20:45 +0000
74+++ config.yaml 2014-05-12 19:08:21 +0000
75@@ -1,5 +1,5 @@
76 options:
77 port:
78 type: int
79- default: 80
80+ default: 3000
81 description: The port number for the tracks webserver
82
83=== added file 'hooks/config-changed'
84--- hooks/config-changed 1970-01-01 00:00:00 +0000
85+++ hooks/config-changed 2014-05-12 19:08:21 +0000
86@@ -0,0 +1,31 @@
87+#!/bin/bash
88+
89+set -eux
90+
91+PORT=`config-get port`
92+
93+if [[ "$PORT" -lt 1025 ]]; then
94+ juju-log "At this time, ports minor than 1024 are not supported. Please, change your port number."
95+ exit 0
96+fi
97+
98+if [[ -f .portnotsupported ]] && [[ "$PORT" -lt 1024 ]]; then
99+ juju-log "Yay, you've set a valid port now. Installing!"
100+ hooks/install
101+ rm .portnotsupported
102+fi
103+
104+if [ -f .port ] && [ `cat .port` != "${PORT}" ]; then
105+ currentport=`cat .port`
106+ juju-log "Switching port to ${PORT}"
107+ close-port ${currentport}/tcp
108+ open-port ${PORT}/tcp
109+ echo "${PORT}" > .port
110+ if [ -f .started ]; then
111+ stop tracksapp
112+ fi
113+ sed -i "s/$currentport/$PORT/" /etc/init/tracksapp.conf
114+ if [ -f .started ]; then
115+ start tracksapp
116+ fi
117+fi
118
119=== modified file 'hooks/db-relation-changed'
120--- hooks/db-relation-changed 2012-11-25 02:33:40 +0000
121+++ hooks/db-relation-changed 2014-05-12 19:08:21 +0000
122@@ -17,30 +17,44 @@
123 juju-log "Retrieved hostname: $hostname"
124
125 juju-log "configuring database.yml to use ${database}"
126-cat > tracks/config/database.yml << EOF
127+cat > /home/tracks/tracks/config/database.yml << EOF
128 production:
129- adapter: mysql
130+ adapter: mysql2
131 database: tracks
132 host: ${mysqlhost}
133 username: ${user}
134 password: ${password}
135 EOF
136
137-juju-log "stopping old instances"
138-# XXX make this grep line more specific
139-PID=`ps -ef | grep "ruby script/server" | grep -v grep | awk '{ print $2 }'`
140-if [[ ! -z ${PID} ]]; then
141- kill ${PID} || true
142+if [ -f .started ]; then
143+ juju-log "stopping old instances"
144+ stop tracksapp
145+ rm .started
146 fi
147
148 juju-log "db:migrate"
149 juju-log `pwd`
150-cd tracks
151+cd /home/tracks/tracks
152 bundle exec rake db:migrate RAILS_ENV=production
153
154 PORT=`config-get port`
155-juju-log "Opening port ${PORT}"
156-open-port ${PORT}/tcp
157-
158-juju-log "Starting Tracks"
159-bundle exec script/server -e production -p 80
160+if [ ! -f $CHARM_DIR/.port ]; then
161+ juju-log "Opening port ${PORT}"
162+ open-port ${PORT}/tcp
163+ echo "${PORT}" > $CHARM_DIR/.port
164+elif [ -f $CHARM_DIR/.port ] && [ `cat $CHARM_DIR/.port` != "${PORT}" ]; then
165+ currentport=`cat $CHARM_DIR/.port`
166+ juju-log "Switching port to ${PORT}"
167+ close-port ${currentport}/tcp
168+ open-port ${PORT}/tcp
169+ echo "${PORT}" > $CHARM_DIR/.port
170+fi
171+
172+juju-log "Setting necessary permissions"
173+chown -hR tracks /home/tracks/tracks
174+
175+if [ ! -f .started ]; then
176+ juju-log "Starting Tracks"
177+ start tracksapp
178+ touch $CHARM_DIR/.started
179+fi
180
181=== modified file 'hooks/install'
182--- hooks/install 2013-02-21 03:31:54 +0000
183+++ hooks/install 2014-05-12 19:08:21 +0000
184@@ -5,17 +5,29 @@
185
186 set -eux
187
188+PORT=`config-get port`
189+
190+juju-log "Checking if port is >1024"
191+if [[ "$PORT" -lt 1025 ]]; then
192+ juju-log "At this point, the use of ports minor than 1025 are not supported. Please, change your port number."
193+ touch .portnotsupported
194+ exit 0
195+fi
196+
197+juju-log "creating user tracks"
198+useradd -rm tracks
199+
200 juju-log "installing pre-reqs"
201+add-apt-repository ppa:brightbox/ruby-ng -y
202 apt-get update
203-apt-get install -qqy unzip ruby-full build-essential libmysqlclient-dev \
204+apt-get install -qqy unzip ruby2.1 build-essential libmysqlclient-dev \
205 libruby sqlite3 libmysql-ruby libmysql-ruby libsqlite3-ruby libsqlite3-dev \
206 imagemagick graphicsmagick libgraphicsmagick1-dev librmagick-ruby \
207-libxslt-dev libxml2-dev pwgen rubygems mysql-client wget
208+libxslt-dev libxml2-dev pwgen rubygems mysql-client wget ruby2.1-dev
209
210 juju-log "installing tracks"
211-wget -O tracks.zip https://github.com/TracksApp/tracks/zipball/v2.1
212-unzip tracks.zip
213-mv TracksApp-tracks-* tracks
214+cd /home/tracks/
215+git clone https://github.com/TracksApp/tracks -b 2.2_branch
216 cd tracks
217 chmod -R 664 *
218 find -type d -exec chmod a+x '{}' \;
219@@ -23,8 +35,6 @@
220
221 juju-log "installing bundler & rake"
222 gem install --source https://rubygems.org/ bundler rake
223-juju-log "correcting gemfile source"
224-sed -i 's/http:\/\/gems.github.com/https:\/\/rubygems.org/' Gemfile
225 juju-log "installing bundles"
226 bundle install --without=test
227
228@@ -37,3 +47,23 @@
229
230 juju-log "fixing htaccess"
231 mv public/.htaccess public/dontneedhtaccess
232+
233+juju-log "fixing error in prod env config"
234+sed -i "s/config.assets.compile \= false/config.assets.compile \= true/" config/environments/production.rb
235+
236+juju-log "creating upstart job"
237+cat > /etc/init/tracksapp.conf << EOF
238+env FOLDER=/home/tracks/tracks
239+env PORT=$PORT
240+
241+setuid tracks
242+
243+pre-start script
244+chdir \$FOLDER
245+end script
246+
247+script
248+chdir \$FOLDER
249+bundle exec rails server -e production -p \$PORT
250+end script
251+EOF
252
253=== modified file 'hooks/stop'
254--- hooks/stop 2012-11-25 02:33:40 +0000
255+++ hooks/stop 2014-05-12 19:08:21 +0000
256@@ -1,8 +1,7 @@
257 #!/bin/bash
258-juju-log "Stopping Tracks"
259-PID=`ps -ef | grep "bundle exec" | grep -v grep | awk '{ print $2 }'`
260-if [[ ! -z ${PID} ]]; then
261- kill ${PID} || true
262+if [ -f .started ]; then
263+ juju-log "Stopping Tracks"
264+ stop tracksapp
265 fi
266 PORT=`config-get port`
267 juju-log "Closing port ${PORT}"
268
269=== added file 'hooks/website-relation-joined'
270--- hooks/website-relation-joined 1970-01-01 00:00:00 +0000
271+++ hooks/website-relation-joined 2014-05-12 19:08:21 +0000
272@@ -0,0 +1,2 @@
273+#!/bin/bash
274+relation-set hostname=`unit-get private-address` port=`config-get port`
275
276=== modified file 'metadata.yaml'
277--- metadata.yaml 2012-11-27 22:20:45 +0000
278+++ metadata.yaml 2014-05-12 19:08:21 +0000
279@@ -6,6 +6,8 @@
280
281 This setup uses a mysql instance and the built-in webserver.
282 maintainer: Matt Fischer <matt@mattfischer.com>
283+categories:
284+ - applications
285 requires:
286 db:
287 interface: mysql

Subscribers

People subscribed via source and target branches

to all changes: