LEFT | RIGHT |
1 package machiner | 1 package machiner |
2 | 2 |
3 import ( | 3 import ( |
4 "launchpad.net/juju-core/container" | 4 "launchpad.net/juju-core/container" |
5 "launchpad.net/juju-core/log" | 5 "launchpad.net/juju-core/log" |
6 "launchpad.net/juju-core/state" | 6 "launchpad.net/juju-core/state" |
7 "launchpad.net/juju-core/state/watcher" | 7 "launchpad.net/juju-core/state/watcher" |
8 "launchpad.net/tomb" | 8 "launchpad.net/tomb" |
9 ) | 9 ) |
10 | 10 |
11 // NewMachiner starts a machine agent running that | 11 // NewMachiner starts a machine agent running that |
12 // deploys agents in the given directory. | 12 // deploys agents in the given directory. |
13 // The Machiner dies when it encounters an error. | 13 // The Machiner dies when it encounters an error. |
14 func NewMachiner(machine *state.Machine, dataDir string) *Machiner { | 14 func NewMachiner(machine *state.Machine, dataDir string) *Machiner { |
15 cont := &container.Simple{DataDir: dataDir} | 15 cont := &container.Simple{DataDir: dataDir} |
16 return newMachiner(machine, cont) | 16 return newMachiner(machine, cont) |
17 } | 17 } |
18 | 18 |
19 func newMachiner(machine *state.Machine, cont container.Container) *Machiner { | 19 func newMachiner(machine *state.Machine, cont container.Container) *Machiner { |
20 m := &Machiner{localContainer: cont} | 20 m := &Machiner{localContainer: cont} |
21 go m.loop(machine) | 21 go m.loop(machine) |
22 return m | 22 return m |
23 } | 23 } |
24 | 24 |
25 // Machiner represents a running machine agent. | 25 // Machiner represents a running machine agent. |
26 type Machiner struct { | 26 type Machiner struct { |
27 » tomb tomb.Tomb | 27 » tomb tomb.Tomb |
28 localContainer container.Container | 28 localContainer container.Container |
29 } | 29 } |
30 | 30 |
31 func (m *Machiner) loop(machine *state.Machine) { | 31 func (m *Machiner) loop(machine *state.Machine) { |
32 defer m.tomb.Done() | 32 defer m.tomb.Done() |
33 w := machine.WatchUnits() | 33 w := machine.WatchUnits() |
34 defer watcher.Stop(w, &m.tomb) | 34 defer watcher.Stop(w, &m.tomb) |
35 | 35 |
36 // TODO read initial units, check if they're running | 36 // TODO read initial units, check if they're running |
37 // and restart them if not. Also track units so | 37 // and restart them if not. Also track units so |
(...skipping 29 matching lines...) Expand all Loading... |
67 // Wait waits until the Machiner has died, and returns the error encountered. | 67 // Wait waits until the Machiner has died, and returns the error encountered. |
68 func (m *Machiner) Wait() error { | 68 func (m *Machiner) Wait() error { |
69 return m.tomb.Wait() | 69 return m.tomb.Wait() |
70 } | 70 } |
71 | 71 |
72 // Stop terminates the Machiner and returns any error that it encountered. | 72 // Stop terminates the Machiner and returns any error that it encountered. |
73 func (m *Machiner) Stop() error { | 73 func (m *Machiner) Stop() error { |
74 m.tomb.Kill(nil) | 74 m.tomb.Kill(nil) |
75 return m.tomb.Wait() | 75 return m.tomb.Wait() |
76 } | 76 } |
LEFT | RIGHT |