示例#1
0
文件: logs.go 项目: 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
}
示例#2
0
文件: connection.go 项目: jxaas/jxaas
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")
}
示例#3
0
func (self *FileByteSource) Exists() (bool, error) {
	return files.Exists(self.path)
}