Пример #1
0
func StopAgentOf(da *model.DesiredAgent, lastRunUser, lastWorkDir string) error {
	agentDir := path.Join(lastWorkDir, da.Name)
	version := ReadVersion(lastRunUser, agentDir)

	if "" == version {
		version = da.Version
	}
	if version == da.Version && da.RunUser == lastRunUser && da.WorkDir == lastWorkDir {
		// do nothing
		return nil
	}

	versionDir := path.Join(agentDir, version)
	if !CheckDirectoryExists(lastRunUser, versionDir) {
		logger.Warn("user: %s, %s nonexistent", lastRunUser, versionDir)
		return nil
	}

	err := ControlStopIn(lastRunUser, versionDir)
	if nil != err {
		return err
	}

	cmd := BuildCommand(lastRunUser, "rm", "-rf", versionDir)
	cmd.Dir = file.SelfDir()
	_, err = ExecuteCommandWithOutput(cmd)
	return err
}
Пример #2
0
func (t *RingBackend) LoadAddrs(f string) error {
	if !file.IsExist(f) {
		return errors.New("backends file is not exist")
	}

	file_content, err := file.ToString(f)
	if err != nil {
		return err
	}
	file_content = strings.Trim(file_content, " \n\t")

	lines := strings.Split(file_content, "\n")
	if len(lines) == 0 {
		return errors.New("empty backends")
	}

	tmp_addrs := make(map[string][]string)
	for _, line := range lines {
		fields := strings.Fields(line)
		size := len(fields)
		if size < 2 {
			logger.Warn("invalid backend %s", line)
			continue
		}
		name := fields[0]
		addr := fields[1:size]
		tmp_addrs[name] = addr
	}

	t.Lock()
	defer t.Unlock()
	t.Addrs = tmp_addrs

	return nil
}
Пример #3
0
func ReadVersion(username, agentDir string) string {
	versionFile := path.Join(agentDir, ".version")
	cmd := BuildCommand(username, "sh", "read_file.sh", versionFile)
	cmd.Dir = file.SelfDir()
	version, err := ExecuteCommandWithOutput(cmd)
	if err != nil {
		logger.Warn("%s is nonexistent,error: %v", versionFile, err)
		return ""
	}
	return version
}