Merge lp:~thumper/juju-core/upstart-services into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1406
Proposed branch: lp:~thumper/juju-core/upstart-services
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~thumper/juju-core/find-ipv4-address
Diff against target: 245 lines (+83/-62)
3 files modified
environs/cloudinit/cloudinit.go (+17/-58)
environs/cloudinit/cloudinit_test.go (+4/-4)
upstart/service.go (+62/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/upstart-services
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+173121@code.launchpad.net

Commit message

Further break up cloudinit.

Move the definitions of the mongo and machine agent
services into the upstart package. These have been
parameterized to allow reuse in the local provider.

https://codereview.appspot.com/10952043/

Description of the change

Further break up cloudinit.

Move the definitions of the mongo and machine agent
services into the upstart package. These have been
parameterized to allow reuse in the local provider.

There definitions have been moved from the cloudinit
function, and as you can see there are two different
ways of defining the command. I have left it up to
the reviewers to decide which is better. Personally
I'm leaning towards the style used to define the
mongo service.

Also, wondering about specific tests for these. They
don't really do much except format the parameters
for a new object.

https://codereview.appspot.com/10952043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+173121_code.launchpad.net,

Message:
Please take a look.

Description:
Further break up cloudinit.

Move the definitions of the mongo and machine agent
services into the upstart package. These have been
parameterized to allow reuse in the local provider.

There definitions have been moved from the cloudinit
function, and as you can see there are two different
ways of defining the command. I have left it up to
the reviewers to decide which is better. Personally
I'm leaning towards the style used to define the
mongo service.

Also, wondering about specific tests for these. They
don't really do much except format the parameters
for a new object.

https://code.launchpad.net/~thumper/juju-core/upstart-services/+merge/173121

Requires:
https://code.launchpad.net/~thumper/juju-core/find-ipv4-address/+merge/173119

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/10952043/

Affected files:
   A [revision details]
   M environs/all/all.go
   M environs/cloudinit/cloudinit.go
   M environs/local/config.go
   M environs/local/config_test.go
   M environs/local/environ.go
   M environs/local/environprovider.go
   M environs/local/environprovider_test.go
   M environs/local/export_test.go
   A upstart/service.go

Revision history for this message
Tim Penhey (thumper) wrote :

Must have switched before lbox had finished making the diff, trying to regenerate.

Revision history for this message
Tim Penhey (thumper) wrote :
Revision history for this message
Frank Mueller (themue) wrote :

I really like the approach, but would also like isolated tests for the
new upstart functions.

https://codereview.appspot.com/10952043/

Revision history for this message
Ian Booth (wallyworld) wrote :

LGTM. I prefer the string concatenation as it's easier to read. I also
don't think tests for the struct creation will add too much value. I see
this as a minor, internal implementation detail. So long as there are
other tests that check things like the contents of the upstart files,
that to me is sufficient.

https://codereview.appspot.com/10952043/

Revision history for this message
Tim Penhey (thumper) wrote :

On 2013/07/08 01:38:17, wallyworld wrote:
> LGTM. I prefer the string concatenation as it's easier to read. I also
don't
> think tests for the struct creation will add too much value. I see
this as a
> minor, internal implementation detail. So long as there are other
tests that
> check things like the contents of the upstart files, that to me is
sufficient.

Restructured.

https://codereview.appspot.com/10952043/

Revision history for this message
Tim Penhey (thumper) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/cloudinit/cloudinit.go'
2--- environs/cloudinit/cloudinit.go 2013-07-01 01:09:16 +0000
3+++ environs/cloudinit/cloudinit.go 2013-07-08 22:36:27 +0000
4@@ -6,7 +6,10 @@
5 import (
6 "encoding/base64"
7 "fmt"
8+ "path/filepath"
9+
10 "launchpad.net/goyaml"
11+
12 "launchpad.net/juju-core/cloudinit"
13 "launchpad.net/juju-core/constraints"
14 "launchpad.net/juju-core/environs/agent"
15@@ -17,12 +20,6 @@
16 "launchpad.net/juju-core/state/api"
17 "launchpad.net/juju-core/upstart"
18 "launchpad.net/juju-core/utils"
19- "path"
20-)
21-
22-const (
23- maxMongoFiles = 65000
24- maxAgentFiles = 20000
25 )
26
27 // MachineConfig represents initialization information for a new juju machine.
28@@ -190,9 +187,7 @@
29 )
30 }
31
32- if err := cfg.addAgentToBoot(c, "machine",
33- machineTag,
34- fmt.Sprintf("--machine-id %s "+debugFlag, cfg.MachineId)); err != nil {
35+ if err := cfg.addMachineAgentToBoot(c, machineTag, cfg.MachineId, debugFlag); err != nil {
36 return nil, err
37 }
38
39@@ -232,7 +227,7 @@
40 }
41
42 func (cfg *MachineConfig) dataFile(name string) string {
43- return path.Join(cfg.DataDir, name)
44+ return filepath.Join(cfg.DataDir, name)
45 }
46
47 func (cfg *MachineConfig) agentConfig(tag string) *agent.Conf {
48@@ -273,7 +268,7 @@
49 return acfg, nil
50 }
51
52-func (cfg *MachineConfig) addAgentToBoot(c *cloudinit.Config, kind, tag, args string) error {
53+func (cfg *MachineConfig) addMachineAgentToBoot(c *cloudinit.Config, tag, machineId, logConfig string) error {
54 // Make the agent run via a symbolic link to the actual tools
55 // directory, so it can upgrade itself without needing to change
56 // the upstart script.
57@@ -281,27 +276,8 @@
58 // TODO(dfc) ln -nfs, so it doesn't fail if for some reason that the target already exists
59 addScripts(c, fmt.Sprintf("ln -s %v %s", cfg.Tools.Binary, shquote(toolsDir)))
60
61- svc := upstart.NewService("jujud-" + tag)
62- logPath := fmt.Sprintf("/var/log/juju/%s.log", tag)
63- cmd := fmt.Sprintf(
64- "%s/jujud %s"+
65- " --log-file %s"+
66- " --data-dir '%s'"+
67- " %s",
68- toolsDir, kind,
69- logPath,
70- cfg.DataDir,
71- args,
72- )
73- conf := &upstart.Conf{
74- Service: *svc,
75- Desc: fmt.Sprintf("juju %s agent", tag),
76- Limit: map[string]string{
77- "nofile": fmt.Sprintf("%d %d", maxAgentFiles, maxAgentFiles),
78- },
79- Cmd: cmd,
80- Out: logPath,
81- }
82+ name := "jujud-" + tag
83+ conf := upstart.MachineAgentUpstartService(name, toolsDir, cfg.DataDir, "/var/log/juju/", tag, machineId, logConfig)
84 cmds, err := conf.InstallCommands()
85 if err != nil {
86 return fmt.Errorf("cannot make cloud-init upstart script for the %s agent: %v", tag, err)
87@@ -311,33 +287,16 @@
88 }
89
90 func (cfg *MachineConfig) addMongoToBoot(c *cloudinit.Config) error {
91+ dbDir := filepath.Join(cfg.DataDir, "db")
92 addScripts(c,
93- "mkdir -p /var/lib/juju/db/journal",
94+ "mkdir -p "+dbDir+"/journal",
95 // Otherwise we get three files with 100M+ each, which takes time.
96- "dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc.0",
97- "dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc.1",
98- "dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc.2",
99+ "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.0",
100+ "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.1",
101+ "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.2",
102 )
103- svc := upstart.NewService("juju-db")
104- conf := &upstart.Conf{
105- Service: *svc,
106- Desc: "juju state database",
107- Limit: map[string]string{
108- "nofile": fmt.Sprintf("%d %d", maxMongoFiles, maxMongoFiles),
109- "nproc": fmt.Sprintf("%d %d", maxAgentFiles, maxAgentFiles),
110- },
111- Cmd: "/usr/bin/mongod" +
112- " --auth" +
113- " --dbpath=/var/lib/juju/db" +
114- " --sslOnNormalPorts" +
115- " --sslPEMKeyFile " + shquote(cfg.dataFile("server.pem")) +
116- " --sslPEMKeyPassword ignored" +
117- " --bind_ip 0.0.0.0" +
118- " --port " + fmt.Sprint(cfg.StatePort) +
119- " --noprealloc" +
120- " --syslog" +
121- " --smallfiles",
122- }
123+
124+ conf := upstart.MongoUpstartService("juju-db", cfg.DataDir, dbDir, cfg.StatePort)
125 cmds, err := conf.InstallCommands()
126 if err != nil {
127 return fmt.Errorf("cannot make cloud-init upstart script for the state database: %v", err)
128@@ -350,8 +309,8 @@
129 // to use as a directory for storing the tools executables in
130 // by using the last element stripped of its extension.
131 func versionDir(toolsURL string) string {
132- name := path.Base(toolsURL)
133- ext := path.Ext(name)
134+ name := filepath.Base(toolsURL)
135+ ext := filepath.Ext(name)
136 return name[:len(name)-len(ext)]
137 }
138
139
140=== modified file 'environs/cloudinit/cloudinit_test.go'
141--- environs/cloudinit/cloudinit_test.go 2013-07-01 12:15:52 +0000
142+++ environs/cloudinit/cloudinit_test.go 2013-07-08 22:36:27 +0000
143@@ -103,7 +103,7 @@
144 /var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --env-config '[^']*' --constraints 'mem=2048M' --debug
145 rm -rf '/var/lib/juju/agents/bootstrap'
146 ln -s 1\.2\.3-precise-amd64 '/var/lib/juju/tools/machine-0'
147-cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --log-file /var/log/juju/machine-0\.log --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
148+cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --log-file '/var/log/juju/machine-0\.log' --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
149 start jujud-machine-0
150 `,
151 }, {
152@@ -158,7 +158,7 @@
153 /var/lib/juju/tools/1\.2\.3-raring-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --env-config '[^']*' --constraints 'mem=2048M' --debug
154 rm -rf '/var/lib/juju/agents/bootstrap'
155 ln -s 1\.2\.3-raring-amd64 '/var/lib/juju/tools/machine-0'
156-cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --log-file /var/log/juju/machine-0\.log --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
157+cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --log-file '/var/log/juju/machine-0\.log' --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
158 start jujud-machine-0
159 `,
160 }, {
161@@ -196,7 +196,7 @@
162 echo 'datadir: /var/lib/juju\\noldpassword: arble\\nmachinenonce: FAKE_NONCE\\nstateinfo:\\n addrs:\\n - state-addr\.example\.com:12345\\n cacert:\\n[^']+ tag: machine-99\\n password: ""\\noldapipassword: ""\\napiinfo:\\n addrs:\\n - state-addr\.example\.com:54321\\n cacert:\\n[^']+ tag: machine-99\\n password: ""\\n' > '/var/lib/juju/agents/machine-99/agent\.conf'
163 chmod 600 '/var/lib/juju/agents/machine-99/agent\.conf'
164 ln -s 1\.2\.3-linux-amd64 '/var/lib/juju/tools/machine-99'
165-cat >> /etc/init/jujud-machine-99\.conf << 'EOF'\\ndescription "juju machine-99 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-99/jujud machine --log-file /var/log/juju/machine-99\.log --data-dir '/var/lib/juju' --machine-id 99 --debug >> /var/log/juju/machine-99\.log 2>&1\\nEOF\\n
166+cat >> /etc/init/jujud-machine-99\.conf << 'EOF'\\ndescription "juju machine-99 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-99/jujud machine --log-file '/var/log/juju/machine-99\.log' --data-dir '/var/lib/juju' --machine-id 99 --debug >> /var/log/juju/machine-99\.log 2>&1\\nEOF\\n
167 start jujud-machine-99
168 `,
169 }, {
170@@ -235,7 +235,7 @@
171 echo 'datadir: /var/lib/juju\\noldpassword: arble\\nmachinenonce: FAKE_NONCE\\nstateinfo:\\n addrs:\\n - state-addr\.example\.com:12345\\n cacert:\\n[^']+ tag: machine-2-lxc-1\\n password: ""\\noldapipassword: ""\\napiinfo:\\n addrs:\\n - state-addr\.example\.com:54321\\n cacert:\\n[^']+ tag: machine-2-lxc-1\\n password: ""\\n' > '/var/lib/juju/agents/machine-2-lxc-1/agent\.conf'
172 chmod 600 '/var/lib/juju/agents/machine-2-lxc-1/agent\.conf'
173 ln -s 1\.2\.3-linux-amd64 '/var/lib/juju/tools/machine-2-lxc-1'
174-cat >> /etc/init/jujud-machine-2-lxc-1\.conf << 'EOF'\\ndescription "juju machine-2-lxc-1 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-2-lxc-1/jujud machine --log-file /var/log/juju/machine-2-lxc-1\.log --data-dir '/var/lib/juju' --machine-id 2/lxc/1 --debug >> /var/log/juju/machine-2-lxc-1\.log 2>&1\\nEOF\\n
175+cat >> /etc/init/jujud-machine-2-lxc-1\.conf << 'EOF'\\ndescription "juju machine-2-lxc-1 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-2-lxc-1/jujud machine --log-file '/var/log/juju/machine-2-lxc-1\.log' --data-dir '/var/lib/juju' --machine-id 2/lxc/1 --debug >> /var/log/juju/machine-2-lxc-1\.log 2>&1\\nEOF\\n
176 start jujud-machine-2-lxc-1
177 `,
178 },
179
180=== added file 'upstart/service.go'
181--- upstart/service.go 1970-01-01 00:00:00 +0000
182+++ upstart/service.go 2013-07-08 22:36:27 +0000
183@@ -0,0 +1,62 @@
184+// Copyright 2013 Canonical Ltd.
185+// Licensed under the AGPLv3, see LICENCE file for details.
186+
187+package upstart
188+
189+import (
190+ "fmt"
191+ "path/filepath"
192+
193+ "launchpad.net/juju-core/utils"
194+)
195+
196+const (
197+ maxMongoFiles = 65000
198+ maxAgentFiles = 20000
199+)
200+
201+// MongoUpstartService returns the upstart config for the mongo state service.
202+func MongoUpstartService(name, dataDir, dbDir string, port int) *Conf {
203+ keyFile := filepath.Join(dataDir, "server.pem")
204+ svc := NewService(name)
205+ return &Conf{
206+ Service: *svc,
207+ Desc: "juju state database",
208+ Limit: map[string]string{
209+ "nofile": fmt.Sprintf("%d %d", maxMongoFiles, maxMongoFiles),
210+ "nproc": fmt.Sprintf("%d %d", maxAgentFiles, maxAgentFiles),
211+ },
212+ Cmd: "/usr/bin/mongod" +
213+ " --auth" +
214+ " --dbpath=" + dbDir +
215+ " --sslOnNormalPorts" +
216+ " --sslPEMKeyFile " + utils.ShQuote(keyFile) +
217+ " --sslPEMKeyPassword ignored" +
218+ " --bind_ip 0.0.0.0" +
219+ " --port " + fmt.Sprint(port) +
220+ " --noprealloc" +
221+ " --syslog" +
222+ " --smallfiles",
223+ }
224+}
225+
226+// MachineAgentUpstartService returns the upstart config for a machine agent
227+// based on the tag and machineId passed in.
228+func MachineAgentUpstartService(name, toolsDir, dataDir, logDir, tag, machineId, logConfig string) *Conf {
229+ svc := NewService(name)
230+ logFile := filepath.Join(logDir, tag+".log")
231+ return &Conf{
232+ Service: *svc,
233+ Desc: fmt.Sprintf("juju %s agent", tag),
234+ Limit: map[string]string{
235+ "nofile": fmt.Sprintf("%d %d", maxAgentFiles, maxAgentFiles),
236+ },
237+ Cmd: filepath.Join(toolsDir, "jujud") +
238+ " machine" +
239+ " --log-file " + utils.ShQuote(logFile) +
240+ " --data-dir " + utils.ShQuote(dataDir) +
241+ " --machine-id " + machineId +
242+ " " + logConfig,
243+ Out: logFile,
244+ }
245+}

Subscribers

People subscribed via source and target branches

to status/vote changes: