1Panel-dev/1Panel · critical

init db dir failed, err: %v

Error message

init db dir failed, err: %v

What it means

Panic in LoadDBConnByPath when createDirWhenNotExist cannot create the parent directory of the SQLite database file (path.Dir(fullPath)). It is a filesystem-level failure: permission denied, read-only mount, or a path component that is a file.

Source

Thrown at agent/utils/common/sqlite.go:18

package common

import (
	"fmt"
	"log"
	"os"
	"path"
	"time"

	"github.com/1Panel-dev/1Panel/agent/global"
	"github.com/glebarez/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

func LoadDBConnByPath(fullPath, dbName string) *gorm.DB {
	if _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {
		panic(fmt.Errorf("init db dir failed, err: %v", err))
	}
	if _, err := os.Stat(fullPath); err != nil {
		f, err := os.Create(fullPath)
		if err != nil {
			panic(fmt.Errorf("init %s db file failed, err: %v", dbName, err))
		}
		_ = f.Close()
	}

	db, err := GetDBWithPath(fullPath)
	if err != nil {
		panic(err)
	}
	return db
}

func LoadDBConnByPathWithErr(fullPath, dbName string) (*gorm.DB, error) {
	if _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {

View on GitHub (pinned to 5ac7c80881)

Solutions

  1. mkdir -p <dir of the db path> and chown it to the user running the agent (e.g. chown -R 1panel:1panel /opt/1panel/db)
  2. Check the volume is mounted rw (mount | grep <path>) and not full (df -h; df -i)
  3. Fix any mistyped DB path in the app config that collides with an existing file

Example fix

# before: agent cannot create db dir
sudo -u 1panel mkdir /opt/1panel/db  # Permission denied
# after
mkdir -p /opt/1panel/db && chown 1panel:1panel /opt/1panel/db
Defensive patterns

Strategy: validation

Validate before calling

sudo -u <agent-user> test -w /opt/1panel/db && echo writable || mkdir -p /opt/1panel/db && chown <agent-user> /opt/1panel/db

Prevention

When it happens

Trigger: agent/utils/common/sqlite.go LoadDBConnByPath(fullPath) is called (agent startup or feature init) with a db path like /opt/1panel/db/foo.db whose parent /opt/1panel/db cannot be created — dir owned by root while agent runs as another user, or /opt/1panel is read-only.

Common situations: Wrong user/permissions after a manual install or restore; container with a read-only volume mounted at the db path; SELinux/AppArmor denying writes; disk or inode exhaustion.

Related errors


AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15). Data as JSON: /api/errors/2f37d91081d74000. Report an issue: GitHub.