Merge lp:~marcoceppi/charms/oneiric/minecraft/trunk into lp:charms/oneiric/minecraft

Proposed by Marco Ceppi on 2012-03-13
Status: Merged
Approved by: Clint Byrum on 2012-03-14
Approved revision: 30
Merged at revision: 25
Proposed branch: lp:~marcoceppi/charms/oneiric/minecraft/trunk
Merge into: lp:charms/oneiric/minecraft
Diff against target: 83 lines (+37/-21)
4 files modified
hooks/install (+25/-20)
hooks/start (+1/-0)
hooks/stop (+4/-1)
hooks/upgrade-charm (+7/-0)
To merge this branch: bzr merge lp:~marcoceppi/charms/oneiric/minecraft/trunk
Reviewer Review Type Date Requested Status
Clint Byrum (community) 2012-03-13 Approve on 2012-03-14
Review via email: mp+97132@code.launchpad.net

Description of the Change

Updated to nix old form of checksum checking (since HTTPS) and added upgrade hook

To post a comment you must log in.
Clint Byrum (clint-fewbar) wrote :

Hi Marco, the download changes look good. +1

The name of 'upgrade' should be 'upgrade-charm' if you mean for it to be runnable by juju.

IMO, upgrade-charm should just call stop, install, config-changed, and start, rather than have a special method just for checking for upgrades, since you might have changed any of those hooks as well.

Also, minor niggle.. 'cmp' is better for comparing binaries than diff.

review: Needs Fixing
27. By Marco Ceppi on 2012-03-13

Proper name for upgrade hook

28. By Marco Ceppi on 2012-03-13

Look! The stop hook does something

29. By Marco Ceppi on 2012-03-13

Updated hooks to be better players at the idempotent game

Marco Ceppi (marcoceppi) wrote :

Hey Clint,

Thanks for the review! I've changed the hook name to follow the proper naming scheme.

Also, per your recommendations I've set the upgrade-charm script to invoke stop, install, start hooks and moved the various logics for each around so they work in tandem with one another and also separately. Just as well I've replaced diff with CMP.

Thanks!

30. By Marco Ceppi on 2012-03-13

Delete the tmp file if we don't use it

Clint Byrum (clint-fewbar) wrote :

Looking quite good, seems a bit more elegant now.

One thing.. stop and start should also be idempotent if possible.. so

if status minecraft | grep -q stop/ ; then
  start minecraft
fi

This just makes things more resilient in case of unexpected system state.. as this asserts start but retains any error checking.

(and yes, we should probably push the logic above all the way back into upstart's 'start' utility so we cane make it something more like 'start --ok-no-change minecraft')

Thats really a nit pick though, the rest looks good. Also another nit.. there's not much good reason to source the scripts instead of run them... and sourcing them means variables used in both scripts might have unexpected values.. so I'd just drop the '. hooks/install' and make it 'hooks/install'. Again, just a nit! Approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/install'
2--- hooks/install 2011-11-16 20:50:43 +0000
3+++ hooks/install 2012-03-13 03:35:22 +0000
4@@ -1,23 +1,28 @@
5 #!/bin/sh
6
7-## https://gist.github.com/1336585
8-
9-juju-log "Installing OpenJDK"
10-apt-get install -y openjdk-6-jre
11-
12-juju-log "Add Minecraft init script"
13-cp opt/minecraft /etc/init/minecraft.conf
14-
15-juju-log "Downloading Minecraft"
16-mkdir -p /opt/minecraft/
17-wget "https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar" -O /opt/minecraft/minecraft_server.jar
18-
19-juju-log "Branching Minecraft Checksum"
20-bzr branch lp:~marcoceppi/charm/oneiric/minecraft/checksum
21-
22-md5sum -c checksum/checksums
23-if [ "$?" -ne 0 ]; then
24- juju-log "Checksum conditions failed! Exiting"
25- exit 2 #Checksum error number, I just made it up for this.
26+apt-get update && apt-get upgrade -y
27+
28+juju-log "Check if we've installed Minecraft before"
29+
30+if [ ! -f "/opt/minecraft/minecraft_server.jar" ]; then
31+ juju-log "Installing OpenJDK"
32+ apt-get install -y openjdk-6-jre charm-helper-sh
33+
34+ juju-log "Add Minecraft init script"
35+ cp opt/minecraft /etc/init/minecraft.conf
36+
37+ juju-log "Downloading Minecraft"
38+ mkdir -p /opt/minecraft/
39+ wget "https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar" -O /opt/minecraft/minecraft_server.jar
40+else
41+ juju-log "Check for upgrades to current installation"
42+ wget "https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar" -O /tmp/minecraft_server.jar
43+ cmp /opt/minecraft/minecraft_server.jar /tmp/minecraft_server.jar > /dev/null
44+
45+ if [ "$?" -ne 0 ]; then
46+ rm -f /opt/minecraft/minecraft_server.jar
47+ mv /tmp/minecraft_server.jar /opt/minecraft/
48+ else
49+ rm -f /tmp/minecraft_server.jar
50+ fi
51 fi
52-
53
54=== modified file 'hooks/start'
55--- hooks/start 2011-11-16 20:50:43 +0000
56+++ hooks/start 2012-03-13 03:35:22 +0000
57@@ -1,3 +1,4 @@
58 #!/bin/bash
59
60+juju-log "Starting Minecraft"
61 start minecraft
62
63=== modified file 'hooks/stop'
64--- hooks/stop 2011-11-15 14:33:40 +0000
65+++ hooks/stop 2012-03-13 03:35:22 +0000
66@@ -1,1 +1,4 @@
67-#!/bin/bash
68+#!/bin/sh
69+
70+juju-log "Stopping Minecraft"
71+stop minecraft
72
73=== added file 'hooks/upgrade-charm'
74--- hooks/upgrade-charm 1970-01-01 00:00:00 +0000
75+++ hooks/upgrade-charm 2012-03-13 03:35:22 +0000
76@@ -0,0 +1,7 @@
77+#!/bin/sh
78+
79+juju-log 'Running an upgrade'
80+
81+. hooks/stop
82+. hooks/install
83+. hooks/start

Subscribers

People subscribed via source and target branches