// upstartService returns an upstart.Service corresponding to the specified // unit. func (ctx *SimpleContext) upstartService(unitName string) *upstart.Service { tag := names.UnitTag(unitName) svcName := "jujud-" + tag svc := upstart.NewService(svcName) svc.InitDir = ctx.initDir return svc }
func (a *MachineAgent) uninstallAgent(agentConfig agent.Config) error { var errors []error agentServiceName := agentConfig.Value(agent.AgentServiceName) if agentServiceName == "" { // For backwards compatibility, handle lack of AgentServiceName. agentServiceName = os.Getenv("UPSTART_JOB") } if agentServiceName != "" { if err := upstart.NewService(agentServiceName).Remove(); err != nil { errors = append(errors, fmt.Errorf("cannot remove service %q: %v", agentServiceName, err)) } } // Remove the juju-run symlink. if err := os.Remove(jujuRun); err != nil && !os.IsNotExist(err) { errors = append(errors, err) } namespace := agentConfig.Value(agent.Namespace) if err := mongo.RemoveService(namespace); err != nil { errors = append(errors, fmt.Errorf("cannot stop/remove mongo service with namespace %q: %v", namespace, err)) } if err := os.RemoveAll(agentConfig.DataDir()); err != nil { errors = append(errors, err) } if len(errors) == 0 { return nil } return fmt.Errorf("uninstall failed: %v", errors) }
// findUpstartJob tries to find an upstart job matching the // given unit name in one of these formats: // jujud-<deployer-tag>:<unit-tag>.conf (for compatibility) // jujud-<unit-tag>.conf (default) func (ctx *SimpleContext) findUpstartJob(unitName string) *upstart.Service { unitsAndJobs, err := ctx.deployedUnitsUpstartJobs() if err != nil { return nil } if job, ok := unitsAndJobs[unitName]; ok { svc := upstart.NewService(job) svc.InitDir = ctx.initDir return svc } return nil }