// Run runs a unit agent. func (a *UnitAgent) Run(ctx *cmd.Context) error { defer a.tomb.Done() if err := a.ReadConfig(a.Tag().String()); err != nil { return err } agentConfig := a.CurrentConfig() agentLogger.Infof("unit agent %v start (%s [%s])", a.Tag().String(), jujuversion.Current, runtime.Compiler) if flags := featureflag.String(); flags != "" { logger.Warningf("developer feature flags enabled: %s", flags) } network.SetPreferIPv6(agentConfig.PreferIPv6()) // Sometimes there are upgrade steps that are needed for each unit. // There are plans afoot to unify the unit and machine agents. When // this happens, there will be a simple helper function for the upgrade // steps to run something for each unit on the machine. Until then, we // need to have the uniter do it, as the overhead of getting a full // upgrade process in the unit agent out weights the current benefits. // So.. since the upgrade steps are all idempotent, we will just call // the upgrade steps when we start the uniter. To be clear, these // should move back to the upgrade package when we do unify the agents. runUpgrades(agentConfig.Tag(), agentConfig.DataDir()) a.runner.StartWorker("api", a.APIWorkers) err := cmdutil.AgentDone(logger, a.runner.Wait()) a.tomb.Kill(err) return err }
// Run runs a machine agent. func (a *MachineAgent) Run(*cmd.Context) error { defer a.tomb.Done() if err := a.ReadConfig(a.Tag().String()); err != nil { return errors.Errorf("cannot read agent configuration: %v", err) } logger.Infof("machine agent %v start (%s [%s])", a.Tag(), jujuversion.Current, runtime.Compiler) if flags := featureflag.String(); flags != "" { logger.Warningf("developer feature flags enabled: %s", flags) } if err := introspection.WriteProfileFunctions(); err != nil { // This isn't fatal, just annoying. logger.Errorf("failed to write profile funcs: %v", err) } // Before doing anything else, we need to make sure the certificate generated for // use by mongo to validate controller connections is correct. This needs to be done // before any possible restart of the mongo service. // See bug http://pad.lv/1434680 if err := a.upgradeCertificateDNSNames(); err != nil { return errors.Annotate(err, "error upgrading server certificate") } if upgradeComplete, err := upgradesteps.NewLock(a); err != nil { return errors.Annotate(err, "error during creating upgrade completion channel") } else { a.upgradeComplete = upgradeComplete } agentConfig := a.CurrentConfig() createEngine := a.makeEngineCreator(agentConfig.UpgradedToVersion()) charmrepo.CacheDir = filepath.Join(agentConfig.DataDir(), "charmcache") if err := a.createJujudSymlinks(agentConfig.DataDir()); err != nil { return err } a.runner.StartWorker("engine", createEngine) // At this point, all workers will have been configured to start close(a.workersStarted) err := a.runner.Wait() switch errors.Cause(err) { case worker.ErrTerminateAgent: err = a.uninstallAgent() case worker.ErrRebootMachine: logger.Infof("Caught reboot error") err = a.executeRebootOrShutdown(params.ShouldReboot) case worker.ErrShutdownMachine: logger.Infof("Caught shutdown error") err = a.executeRebootOrShutdown(params.ShouldShutdown) } err = cmdutil.AgentDone(logger, err) a.tomb.Kill(err) return err }
// Run runs a unit agent. func (a *UnitAgent) Run(ctx *cmd.Context) error { defer a.tomb.Done() if err := a.ReadConfig(a.Tag().String()); err != nil { return err } agentLogger.Infof("unit agent %v start (%s [%s])", a.Tag().String(), jujuversion.Current, runtime.Compiler) if flags := featureflag.String(); flags != "" { logger.Warningf("developer feature flags enabled: %s", flags) } a.runner.StartWorker("api", a.APIWorkers) err := cmdutil.AgentDone(logger, a.runner.Wait()) a.tomb.Kill(err) return err }