コード例 #1
0
ファイル: simple.go プロジェクト: prabhakhar/juju-core
// upstartService returns an upstart.Service corresponding to the specified
// unit. Its name is badged according to the entity responsible for the
// context, so as to distinguish its own jobs from those installed by other
// means.
func (mgr *SimpleManager) upstartService(unitName string) *upstart.Service {
	entityName := state.UnitEntityName(unitName)
	svcName := "jujud-" + mgr.StateInfo.EntityName + ":" + entityName
	svc := upstart.NewService(svcName)
	svc.InitDir = mgr.InitDir
	return svc
}
コード例 #2
0
ファイル: simple_test.go プロジェクト: prabhakhar/juju-core
func (fix *SimpleToolsFixture) checkUnitRemoved(c *C, name, xName string) {
	entityName := state.UnitEntityName(name)
	confPath, agentDir, toolsDir := fix.paths(entityName, xName)
	for _, path := range []string{confPath, agentDir, toolsDir} {
		_, err := ioutil.ReadFile(path)
		c.Assert(os.IsNotExist(err), Equals, true)
	}
}
コード例 #3
0
ファイル: unit.go プロジェクト: prabhakhar/juju-core
// Run runs a unit agent.
func (a *UnitAgent) Run(ctx *cmd.Context) error {
	if err := a.Conf.read(state.UnitEntityName(a.UnitName)); err != nil {
		return err
	}
	defer log.Printf("cmd/jujud: unit agent exiting")
	defer a.tomb.Done()
	return RunLoop(a.Conf.Conf, a)
}
コード例 #4
0
ファイル: simple.go プロジェクト: prabhakhar/juju-core
func (mgr *SimpleManager) RecallUnit(unitName string) error {
	svc := mgr.upstartService(unitName)
	if !svc.Installed() {
		return fmt.Errorf("unit %q is not deployed", unitName)
	}
	if err := svc.Remove(); err != nil {
		return err
	}
	entityName := state.UnitEntityName(unitName)
	agentDir := environs.AgentDir(mgr.DataDir, entityName)
	if err := os.RemoveAll(agentDir); err != nil {
		return err
	}
	toolsDir := environs.AgentToolsDir(mgr.DataDir, entityName)
	return os.Remove(toolsDir)
}
コード例 #5
0
ファイル: simple_test.go プロジェクト: prabhakhar/juju-core
func (fix *SimpleToolsFixture) checkUnitInstalled(c *C, name, xName, password string) {
	entityName := state.UnitEntityName(name)
	uconfPath, _, toolsDir := fix.paths(entityName, xName)
	uconfData, err := ioutil.ReadFile(uconfPath)
	c.Assert(err, IsNil)
	uconf := string(uconfData)
	var execLine string
	for _, line := range strings.Split(uconf, "\n") {
		if strings.HasPrefix(line, "exec ") {
			execLine = line
			break
		}
	}
	if execLine == "" {
		c.Fatalf("no command found in %s:\n%s", uconfPath, uconf)
	}
	logPath := filepath.Join(fix.logDir, entityName+".log")
	jujudPath := filepath.Join(toolsDir, "jujud")
	for _, pat := range []string{
		"^exec " + jujudPath + " unit ",
		" --unit-name " + name + " ",
		" >> " + logPath + " 2>&1$",
	} {
		match, err := regexp.MatchString(pat, execLine)
		c.Assert(err, IsNil)
		if !match {
			c.Fatalf("failed to match:\n%s\nin:\n%s", pat, execLine)
		}
	}

	conf, err := agent.ReadConf(fix.dataDir, entityName)
	c.Assert(err, IsNil)
	c.Assert(conf, DeepEquals, &agent.Conf{
		DataDir:     fix.dataDir,
		OldPassword: password,
		StateInfo: &state.Info{
			Addrs:      []string{"s1:123", "s2:123"},
			CACert:     []byte("test-cert"),
			EntityName: entityName,
		},
	})

	jujudData, err := ioutil.ReadFile(jujudPath)
	c.Assert(err, IsNil)
	c.Assert(string(jujudData), Equals, fakeJujud)
}
コード例 #6
0
ファイル: simple.go プロジェクト: prabhakhar/juju-core
func (mgr *SimpleManager) DeployUnit(unitName, initialPassword string) (err error) {
	// Check sanity.
	svc := mgr.upstartService(unitName)
	if svc.Installed() {
		return fmt.Errorf("unit %q is already deployed", unitName)
	}

	// Link the current tools for use by the new agent.
	entityName := state.UnitEntityName(unitName)
	_, err = environs.ChangeAgentTools(mgr.DataDir, entityName, version.Current)
	toolsDir := environs.AgentToolsDir(mgr.DataDir, entityName)
	defer removeOnErr(&err, toolsDir)

	info := *mgr.StateInfo
	// Prepare the agent's configuration data.
	conf := &agent.Conf{
		DataDir:     mgr.DataDir,
		OldPassword: initialPassword,
		StateInfo:   &info,
	}
	conf.StateInfo.EntityName = entityName
	conf.StateInfo.Password = ""
	if err := conf.Write(); err != nil {
		return err
	}
	defer removeOnErr(&err, conf.Dir())

	// Install an upstart job that runs the unit agent.
	logPath := filepath.Join(mgr.LogDir, entityName+".log")
	cmd := strings.Join([]string{
		filepath.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,
	}
	return uconf.Install()
}
コード例 #7
0
ファイル: unit.go プロジェクト: prabhakhar/juju-core
func (a *UnitAgent) EntityName() string {
	return state.UnitEntityName(a.UnitName)
}
コード例 #8
0
ファイル: unit_test.go プロジェクト: prabhakhar/juju-core
func (s *UnitSuite) TestUnitEntityName(c *C) {
	c.Assert(state.UnitEntityName("wordpress/2"), Equals, "unit-wordpress-2")
}