// RunOnce runs a unit agent once. func (a *UnitAgent) RunOnce(st *state.State, e AgentState) error { unit := e.(*state.Unit) tasks := []task{ uniter.NewUniter(st, unit.Name(), a.Conf.DataDir), NewUpgrader(st, unit, a.Conf.DataDir), } if unit.IsPrincipal() { tasks = append(tasks, newDeployer(st, unit.WatchSubordinateUnits(), a.Conf.DataDir)) } return runTasks(a.tomb.Dying(), tasks...) }
// StateWorkers returns a worker that runs the unit agent workers. func (a *UnitAgent) StateWorkers() (worker.Worker, error) { st, entity, err := openState(a.Conf.Conf, a) if err != nil { return nil, err } unit := entity.(*state.Unit) dataDir := a.Conf.DataDir runner := worker.NewRunner(allFatal, moreImportant) runner.StartWorker("uniter", func() (worker.Worker, error) { return uniter.NewUniter(st, unit.Name(), dataDir), nil }) return newCloseWorker(runner, st), nil }
// Workers returns a worker that runs the unit agent workers. func (a *UnitAgent) Workers() (worker.Worker, error) { st, entity, err := openState(a.Conf.Conf, a) if err != nil { return nil, err } if err := EnsureAPIInfo(a.Conf.Conf, st, entity); err != nil { // We suppress this error, because it is probably more interesting // to see other failures, but we log it, in case it is a root cause agentLogger.Warningf("error while calling EnsureAPIInfo: %v", err) } unit := entity.(*state.Unit) dataDir := a.Conf.DataDir runner := worker.NewRunner(allFatal, moreImportant) runner.StartWorker("upgrader", func() (worker.Worker, error) { return NewUpgrader(st, unit, dataDir), nil }) runner.StartWorker("uniter", func() (worker.Worker, error) { return uniter.NewUniter(st, unit.Name(), dataDir), nil }) return newCloseWorker(runner, st), nil }
func (s startUniter) step(c *C, ctx *context) { if ctx.uniter != nil { panic("don't start two uniters!") } ctx.uniter = uniter.NewUniter(ctx.st, "u/0", ctx.dataDir) }