Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package cloudinit | 4 package cloudinit |
5 | 5 |
6 import ( | 6 import ( |
7 "encoding/base64" | 7 "encoding/base64" |
8 "encoding/json" | 8 "encoding/json" |
9 "fmt" | 9 "fmt" |
10 "path" | 10 "path" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 }) | 301 }) |
302 } | 302 } |
303 | 303 |
304 // addAgentInfo adds agent-required information to the agent's directory | 304 // addAgentInfo adds agent-required information to the agent's directory |
305 // and returns the agent directory name. | 305 // and returns the agent directory name. |
306 func (cfg *MachineConfig) addAgentInfo(c *cloudinit.Config, tag string) (agent.C onfig, error) { | 306 func (cfg *MachineConfig) addAgentInfo(c *cloudinit.Config, tag string) (agent.C onfig, error) { |
307 acfg, err := cfg.agentConfig(tag) | 307 acfg, err := cfg.agentConfig(tag) |
308 if err != nil { | 308 if err != nil { |
309 return nil, err | 309 return nil, err |
310 } | 310 } |
311 acfg.SetValue(agent.AgentServiceName, machineAgentServiceName(tag)) | |
312 if cfg.StateServer { | |
313 acfg.SetValue(agent.MongoServiceName, mongoServiceName) | |
rog
2013/11/19 09:50:39
Is there nowhere to test this functionality?
axw
2013/11/19 10:23:10
Gah, I intended to do that, it just slipped my min
| |
314 } | |
311 cmds, err := acfg.WriteCommands() | 315 cmds, err := acfg.WriteCommands() |
312 if err != nil { | 316 if err != nil { |
313 return nil, err | 317 return nil, err |
314 } | 318 } |
315 c.AddScripts(cmds...) | 319 c.AddScripts(cmds...) |
316 return acfg, nil | 320 return acfg, nil |
317 } | 321 } |
318 | 322 |
323 const mongoServiceName = "juju-db" | |
324 | |
325 func machineAgentServiceName(tag string) string { | |
326 return "jujud-" + tag | |
327 } | |
328 | |
319 func (cfg *MachineConfig) addMachineAgentToBoot(c *cloudinit.Config, tag, machin eId string) error { | 329 func (cfg *MachineConfig) addMachineAgentToBoot(c *cloudinit.Config, tag, machin eId string) error { |
320 // Make the agent run via a symbolic link to the actual tools | 330 // Make the agent run via a symbolic link to the actual tools |
321 // directory, so it can upgrade itself without needing to change | 331 // directory, so it can upgrade itself without needing to change |
322 // the upstart script. | 332 // the upstart script. |
323 toolsDir := agenttools.ToolsDir(cfg.DataDir, tag) | 333 toolsDir := agenttools.ToolsDir(cfg.DataDir, tag) |
324 // TODO(dfc) ln -nfs, so it doesn't fail if for some reason that the tar get already exists | 334 // TODO(dfc) ln -nfs, so it doesn't fail if for some reason that the tar get already exists |
325 c.AddScripts(fmt.Sprintf("ln -s %v %s", cfg.Tools.Version, shquote(tools Dir))) | 335 c.AddScripts(fmt.Sprintf("ln -s %v %s", cfg.Tools.Version, shquote(tools Dir))) |
326 | 336 |
327 » name := "jujud-" + tag | 337 » name := machineAgentServiceName(tag) |
328 conf := upstart.MachineAgentUpstartService(name, toolsDir, cfg.DataDir, "/var/log/juju/", tag, machineId, nil) | 338 conf := upstart.MachineAgentUpstartService(name, toolsDir, cfg.DataDir, "/var/log/juju/", tag, machineId, nil) |
329 cmds, err := conf.InstallCommands() | 339 cmds, err := conf.InstallCommands() |
330 if err != nil { | 340 if err != nil { |
331 return fmt.Errorf("cannot make cloud-init upstart script for the %s agent: %v", tag, err) | 341 return fmt.Errorf("cannot make cloud-init upstart script for the %s agent: %v", tag, err) |
332 } | 342 } |
333 c.AddScripts(cmds...) | 343 c.AddScripts(cmds...) |
334 return nil | 344 return nil |
335 } | 345 } |
336 | 346 |
337 func (cfg *MachineConfig) addMongoToBoot(c *cloudinit.Config) error { | 347 func (cfg *MachineConfig) addMongoToBoot(c *cloudinit.Config) error { |
338 dbDir := path.Join(cfg.DataDir, "db") | 348 dbDir := path.Join(cfg.DataDir, "db") |
339 c.AddScripts( | 349 c.AddScripts( |
340 "mkdir -p "+dbDir+"/journal", | 350 "mkdir -p "+dbDir+"/journal", |
341 "chmod 0700 "+dbDir, | 351 "chmod 0700 "+dbDir, |
342 // Otherwise we get three files with 100M+ each, which takes tim e. | 352 // Otherwise we get three files with 100M+ each, which takes tim e. |
343 "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.0", | 353 "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.0", |
344 "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.1", | 354 "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.1", |
345 "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.2", | 355 "dd bs=1M count=1 if=/dev/zero of="+dbDir+"/journal/prealloc.2", |
346 ) | 356 ) |
347 | 357 |
348 » conf := upstart.MongoUpstartService("juju-db", cfg.DataDir, dbDir, cfg.S tatePort) | 358 » name := mongoServiceName |
359 » conf := upstart.MongoUpstartService(name, cfg.DataDir, dbDir, cfg.StateP ort) | |
349 cmds, err := conf.InstallCommands() | 360 cmds, err := conf.InstallCommands() |
350 if err != nil { | 361 if err != nil { |
351 return fmt.Errorf("cannot make cloud-init upstart script for the state database: %v", err) | 362 return fmt.Errorf("cannot make cloud-init upstart script for the state database: %v", err) |
352 } | 363 } |
353 c.AddScripts(cmds...) | 364 c.AddScripts(cmds...) |
354 return nil | 365 return nil |
355 } | 366 } |
356 | 367 |
357 // versionDir converts a tools URL into a name | 368 // versionDir converts a tools URL into a name |
358 // to use as a directory for storing the tools executables in | 369 // to use as a directory for storing the tools executables in |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 } | 542 } |
532 if cfg.APIInfo.Tag != names.MachineTag(cfg.MachineId) { | 543 if cfg.APIInfo.Tag != names.MachineTag(cfg.MachineId) { |
533 return fmt.Errorf("entity tag must match started machine ") | 544 return fmt.Errorf("entity tag must match started machine ") |
534 } | 545 } |
535 } | 546 } |
536 if cfg.MachineNonce == "" { | 547 if cfg.MachineNonce == "" { |
537 return fmt.Errorf("missing machine nonce") | 548 return fmt.Errorf("missing machine nonce") |
538 } | 549 } |
539 return nil | 550 return nil |
540 } | 551 } |
OLD | NEW |