Exemplo n.º 1
0
Arquivo: logs.go Projeto: jxaas/jxaas
func (self *JujuLogStore) ReadLog(service string, unitId int) (*JujuLog, error) {
	// TODO: Block path traversal
	filename := "unit-" + service + "-" + strconv.Itoa(unitId) + ".log"
	path := path.Join(self.BaseDir, filename)
	ok, err := files.Exists(path)
	if err != nil {
		return nil, err
	}
	if !ok {
		log.Debug("Log file not found: %v", path)
		return nil, nil
	}
	log := &JujuLog{}
	log.path = path
	return log, nil
}
Exemplo n.º 2
0
func (self *Client) GetLogStore() (*JujuLogStore, error) {
	// TODO: Cache?
	// TODO: SSH?

	baseDir := "/var/log/juju/"
	exists, err := files.Exists(baseDir)
	if err != nil {
		log.Warn("Error checking if /var/log/juju exists", err)
		return nil, err
	}

	logStore := &JujuLogStore{}

	if exists {
		logStore.BaseDir = baseDir
		return logStore, nil
	}

	// LXC looks like /var/log/juju-<username>-local/

	dirs, err := ioutil.ReadDir("/var/log")
	if err != nil {
		log.Warn("Error listing contents of /var/log", err)
		return nil, err
	}

	for _, dir := range dirs {
		if !dir.IsDir() {
			continue
		}

		name := dir.Name()
		if strings.HasPrefix(name, "juju-") && strings.HasSuffix(name, "-local") {
			logStore.BaseDir = filepath.Join("/var/log", name)
			return logStore, nil
		}
	}

	return nil, errors.New("Unable to find juju log store")
}
Exemplo n.º 3
0
func (self *FileByteSource) Exists() (bool, error) {
	return files.Exists(self.path)
}