LEFT | RIGHT |
1 package uniter | 1 package uniter |
2 | 2 |
3 import ( | 3 import ( |
4 "errors" | 4 "errors" |
5 "fmt" | 5 "fmt" |
6 "launchpad.net/juju-core/cmd" | 6 "launchpad.net/juju-core/cmd" |
7 "launchpad.net/juju-core/cmd/jujuc/server" | 7 "launchpad.net/juju-core/cmd/jujuc/server" |
8 "launchpad.net/juju-core/log" | 8 "launchpad.net/juju-core/log" |
9 "launchpad.net/juju-core/state" | 9 "launchpad.net/juju-core/state" |
10 "launchpad.net/juju-core/state/presence" | 10 "launchpad.net/juju-core/state/presence" |
(...skipping 19 matching lines...) Expand all Loading... |
30 service *state.Service | 30 service *state.Service |
31 hook *hook.StateFile | 31 hook *hook.StateFile |
32 charm *charm.Manager | 32 charm *charm.Manager |
33 rand *rand.Rand | 33 rand *rand.Rand |
34 pinger *presence.Pinger | 34 pinger *presence.Pinger |
35 } | 35 } |
36 | 36 |
37 // NewUniter creates a new Uniter which will install, run, and upgrade a | 37 // NewUniter creates a new Uniter which will install, run, and upgrade a |
38 // charm on behalf of the named unit, by executing hooks and operations | 38 // charm on behalf of the named unit, by executing hooks and operations |
39 // provoked by changes in st. | 39 // provoked by changes in st. |
40 func NewUniter(st *state.State, name string, varDir string) (u *Uniter, err erro
r) { | 40 func NewUniter(st *state.State, name string, dataDir string) (u *Uniter, err err
or) { |
41 defer trivial.ErrorContextf(&err, "failed to create uniter for unit %q",
name) | 41 defer trivial.ErrorContextf(&err, "failed to create uniter for unit %q",
name) |
42 » path, err := ensureFs(varDir, name) | 42 » path, err := ensureFs(dataDir, name) |
43 if err != nil { | 43 if err != nil { |
44 return nil, err | 44 return nil, err |
45 } | 45 } |
46 unit, err := st.Unit(name) | 46 unit, err := st.Unit(name) |
47 if err != nil { | 47 if err != nil { |
48 return nil, err | 48 return nil, err |
49 } | 49 } |
50 service, err := st.Service(unit.ServiceName()) | 50 service, err := st.Service(unit.ServiceName()) |
51 if err != nil { | 51 if err != nil { |
52 return nil, err | 52 return nil, err |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // TODO: commit relation state changes. | 192 // TODO: commit relation state changes. |
193 } | 193 } |
194 if err := u.hook.Write(hi, hook.Complete); err != nil { | 194 if err := u.hook.Write(hi, hook.Complete); err != nil { |
195 return err | 195 return err |
196 } | 196 } |
197 log.Printf("hook complete") | 197 log.Printf("hook complete") |
198 return nil | 198 return nil |
199 } | 199 } |
200 | 200 |
201 // ensureFs ensures that files and directories required by the named uniter | 201 // ensureFs ensures that files and directories required by the named uniter |
202 // exist inside varDir. It returns the path to the directory within which the un
iter must | 202 // exist inside dataDir. It returns the path to the directory within which the u
niter must |
203 // store its data. | 203 // store its data. |
204 func ensureFs(varDir, name string) (string, error) { | 204 func ensureFs(dataDir, name string) (string, error) { |
205 // TODO: do this OAOO at packaging time? | 205 // TODO: do this OAOO at packaging time? |
206 » if err := EnsureJujucSymlinks(varDir, name); err != nil { | 206 » if err := EnsureJujucSymlinks(dataDir, name); err != nil { |
207 return "", err | 207 return "", err |
208 } | 208 } |
209 » path := filepath.Join(varDir, "units", strings.Replace(name, "/", "-", 1
)) | 209 » path := filepath.Join(dataDir, "units", strings.Replace(name, "/", "-",
1)) |
210 if err := trivial.EnsureDir(filepath.Join(path, "state")); err != nil { | 210 if err := trivial.EnsureDir(filepath.Join(path, "state")); err != nil { |
211 return "", err | 211 return "", err |
212 } | 212 } |
213 return path, nil | 213 return path, nil |
214 } | 214 } |
LEFT | RIGHT |