func (ctx *SimpleContext) RecallUnit(unitName string) error { svc := ctx.findUpstartJob(unitName) if svc == nil || !svc.Installed() { return fmt.Errorf("unit %q is not deployed", unitName) } if err := svc.Remove(); err != nil { return err } tag := names.UnitTag(unitName) agentDir := tools.Dir(ctx.dataDir, tag) if err := os.RemoveAll(agentDir); err != nil { return err } if err := os.Remove(ctx.syslogConfigPath); err != nil && !os.IsNotExist(err) { logger.Warningf("installer: cannot remove %q: %v", ctx.syslogConfigPath, err) } // Defer this so a failure here does not impede the cleanup (as in tests). defer func() { if err := syslog.Restart(); err != nil { logger.Warningf("installer: cannot restart syslog daemon: %v", err) } }() toolsDir := tools.ToolsDir(ctx.dataDir, tag) return os.Remove(toolsDir) }
func (fix *SimpleToolsFixture) paths(tag string) (confPath, agentDir, toolsDir, syslogConfPath string) { confName := fmt.Sprintf("jujud-%s.conf", tag) confPath = filepath.Join(fix.initDir, confName) agentDir = tools.Dir(fix.dataDir, tag) toolsDir = tools.ToolsDir(fix.dataDir, tag) syslogConfPath = filepath.Join(fix.syslogConfigDir, fmt.Sprintf("26-juju-%s.conf", tag)) return }
// ReadConf reads configuration data for the given // entity from the given data directory. func ReadConf(dataDir, tag string) (*Conf, error) { dir := tools.Dir(dataDir, tag) data, err := ioutil.ReadFile(path.Join(dir, "agent.conf")) if err != nil { return nil, err } var c Conf if err := goyaml.Unmarshal(data, &c); err != nil { return nil, err } c.DataDir = dataDir if err := c.Check(); err != nil { return nil, err } if c.StateInfo != nil { c.StateInfo.Tag = tag } if c.APIInfo != nil { c.APIInfo.Tag = tag } return &c, nil }
// Dir returns the agent's directory. func (c *Conf) Dir() string { return tools.Dir(c.DataDir, c.Tag()) }