henrygd/beszel · error

data directory not found

Error message

data directory not found

What it means

GetDataDir scans a list of candidate directories and returns the first one that passes isValidDataDir. When every candidate fails validation (or none exist), it gives up and returns this sentinel error. It means the agent could not locate (or create) a usable data directory for storing its fingerprint and other state.

Source

Thrown at agent/data_dir.go:67

		exists, _ := directoryExists(path)
		if exists {
			continue
		}

		if err := os.MkdirAll(path, 0755); err != nil {
			continue
		}

		// Verify the created directory is actually writable
		writable, _ := directoryIsWritable(path)
		if !writable {
			continue
		}

		return path, nil
	}

	return "", errors.New("data directory not found")
}

func isValidDataDir(path string, createIfNotExists bool) (bool, error) {
	exists, err := directoryExists(path)
	if err != nil {
		return false, err
	}

	if !exists {
		if !createIfNotExists {
			return false, nil
		}
		if err = os.MkdirAll(path, 0755); err != nil {
			return false, err
		}
	}

	// Always check if the directory is writable

View on GitHub (pinned to b38fb7dafa)

Solutions

  1. Create the expected data directory and grant the agent's user read/write permissions (e.g. mkdir -p /etc/beszel && chown beszel:beszel /etc/beszel).
  2. Check the HOME/working directory environment of the service unit or container so the candidate path actually exists for the running user.
  3. Run the agent once in the foreground with debug logs to see which candidate paths are tried and why each fails isValidDataDir.
  4. If using a container, mount a persistent volume at the expected data path so it survives restarts.

Example fix

// before (dir missing, agent runs as 'beszel' user)
$ ls /etc/beszel
ls: cannot access '/etc/beszel': No such file or directory

// after
$ sudo mkdir -p /etc/beszel
$ sudo chown beszel:beszel /etc/beszel
$ sudo systemctl restart beszel-agent
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat("/etc/beszel"); err != nil {
    log.Printf("data dir missing: %v — create it and grant write access to the agent user", err)
}

Try / catch

dir, err := agent.GetDataDir()
if err != nil {
    if err.Error() == "data directory not found" {
        os.MkdirAll(expectedDir, 0o755)
        dir, err = agent.GetDataDir()
    }
    if err != nil {
        log.Fatalf("no usable data dir: %v", err)
    }
}

Prevention

When it happens

Trigger: Calling agent.GetDataDir() when all candidate paths either do not exist and createIfNotExists is false, exist but fail directoryExists checks, fail permission checks (not writable/readable), or the candidate list itself is empty.

Common situations: Running the agent as a service under a user whose HOME differs from the interactive user; read-only or missing /etc/beszel or ~/.beszel directories; restricted container images where the expected data path was never created; permission changes after package upgrades.

Related errors


AI-assisted analysis of henrygd/beszel@b38fb7dafa (2026-08-31). Data as JSON: /api/errors/2daf6d7faa11231e. Report an issue: GitHub.