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 main | 4 package main |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "os" | 8 "os" |
9 "path/filepath" | 9 "path/filepath" |
10 "time" | 10 "time" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 log.Errorf("running machine %v agent on inappropriate instance", m) | 297 log.Errorf("running machine %v agent on inappropriate instance", m) |
298 return nil, worker.ErrTerminateAgent | 298 return nil, worker.ErrTerminateAgent |
299 } | 299 } |
300 return m, nil | 300 return m, nil |
301 } | 301 } |
302 | 302 |
303 func (a *MachineAgent) Tag() string { | 303 func (a *MachineAgent) Tag() string { |
304 return names.MachineTag(a.MachineId) | 304 return names.MachineTag(a.MachineId) |
305 } | 305 } |
306 | 306 |
307 func (m *MachineAgent) uninstallAgent() error { | 307 func (a *MachineAgent) uninstallAgent() error { |
308 » // TODO(axw) get this from agent config when it's available | 308 » // NOTE: this will not stop/remove upstart services |
309 » name := os.Getenv("UPSTART_JOB") | 309 » // for the local provider (only), which has different |
310 » if name != "" { | 310 » // service names for different users/environments. |
311 » » return upstart.NewService(name).Remove() | 311 » service := upstart.NewService(upstart.MachineAgentServiceName(a.Conf.con fig.Tag())) |
312 » if err := service.Remove(); err != nil { | |
313 » » return err | |
jameinel
2013/11/18 09:56:46
I wonder if we actually want to just return here.
axw
2013/11/19 08:22:54
Fair call. I'll update to do that.
| |
312 } | 314 } |
313 » return nil | 315 » // The machine agent may terminate without knowing its jobs, |
316 » // for example if the machine's entry in state was removed. | |
317 » // Thus, we do not rely on jobs here, and instead just check | |
318 » // if the upstart config exists. | |
319 » service = upstart.NewService(upstart.MongoServiceName) | |
320 » if err := service.StopAndRemove(); err != nil { | |
321 » » return err | |
322 » } | |
323 » return os.RemoveAll(a.Conf.dataDir) | |
314 } | 324 } |
315 | 325 |
316 // Below pieces are used for testing,to give us access to the *State opened | 326 // Below pieces are used for testing,to give us access to the *State opened |
317 // by the agent, and allow us to trigger syncs without waiting 5s for them | 327 // by the agent, and allow us to trigger syncs without waiting 5s for them |
318 // to happen automatically. | 328 // to happen automatically. |
319 | 329 |
320 var stateReporter chan<- *state.State | 330 var stateReporter chan<- *state.State |
321 | 331 |
322 func reportOpenedState(st *state.State) { | 332 func reportOpenedState(st *state.State) { |
323 select { | 333 select { |
(...skipping 14 matching lines...) Expand all Loading... | |
338 select { | 348 select { |
339 case apiReporter <- st: | 349 case apiReporter <- st: |
340 default: | 350 default: |
341 } | 351 } |
342 } | 352 } |
343 func sendOpenedAPIs(dst chan<- *api.State) (undo func()) { | 353 func sendOpenedAPIs(dst chan<- *api.State) (undo func()) { |
344 var original chan<- *api.State | 354 var original chan<- *api.State |
345 original, apiReporter = apiReporter, dst | 355 original, apiReporter = apiReporter, dst |
346 return func() { apiReporter = original } | 356 return func() { apiReporter = original } |
347 } | 357 } |
OLD | NEW |