コード例 #1
0
ファイル: simple.go プロジェクト: CSRedRat/juju-core
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 := state.UnitTag(unitName)
	agentDir := agent.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 := agent.ToolsDir(ctx.dataDir, tag)
	return os.Remove(toolsDir)
}
コード例 #2
0
ファイル: simple.go プロジェクト: CSRedRat/juju-core
func (ctx *SimpleContext) DeployUnit(unitName, initialPassword string) (err error) {
	// Check sanity.
	svc := ctx.upstartService(unitName)
	if svc.Installed() {
		return fmt.Errorf("unit %q is already deployed", unitName)
	}

	// Link the current tools for use by the new agent.
	tag := state.UnitTag(unitName)
	_, err = agent.ChangeAgentTools(ctx.dataDir, tag, version.Current)
	toolsDir := agent.ToolsDir(ctx.dataDir, tag)
	defer removeOnErr(&err, toolsDir)

	// Retrieve addresses from state.
	stateAddrs, err := ctx.addresser.Addresses()
	if err != nil {
		return err
	}
	apiAddrs, err := ctx.addresser.APIAddresses()
	if err != nil {
		return err
	}

	stateInfo := state.Info{
		Addrs:  stateAddrs,
		Tag:    tag,
		CACert: ctx.caCert,
	}
	apiInfo := api.Info{
		Addrs:  apiAddrs,
		Tag:    tag,
		CACert: ctx.caCert,
	}
	// Prepare the agent's configuration data.
	conf := &agent.Conf{
		DataDir:     ctx.dataDir,
		OldPassword: initialPassword,
		StateInfo:   &stateInfo,
		APIInfo:     &apiInfo,
	}
	if err := conf.Write(); err != nil {
		return err
	}
	defer removeOnErr(&err, conf.Dir())

	// Install an upstart job that runs the unit agent.
	logPath := path.Join(ctx.logDir, tag+".log")
	syslogConfigRenderer := syslog.NewForwardConfig(tag, stateAddrs)
	syslogConfigRenderer.ConfigDir = ctx.syslogConfigDir
	syslogConfigRenderer.ConfigFileName = fmt.Sprintf("26-juju-%s.conf", tag)
	if err := syslogConfigRenderer.Write(); err != nil {
		return err
	}
	ctx.syslogConfigPath = syslogConfigRenderer.ConfigFilePath()
	if err := syslog.Restart(); err != nil {
		logger.Warningf("installer: cannot restart syslog daemon: %v", err)
	}
	defer removeOnErr(&err, ctx.syslogConfigPath)

	cmd := strings.Join([]string{
		path.Join(toolsDir, "jujud"), "unit",
		"--data-dir", conf.DataDir,
		"--unit-name", unitName,
		"--debug", // TODO: propagate debug state sensibly
	}, " ")
	uconf := &upstart.Conf{
		Service: *svc,
		Desc:    "juju unit agent for " + unitName,
		Cmd:     cmd,
		Out:     logPath,
		// Propagate the provider type enviroment variable.
		Env: map[string]string{
			"JUJU_PROVIDER_TYPE": os.Getenv("JUJU_PROVIDER_TYPE"),
		},
	}
	return uconf.Install()
}