1Panel-dev/1Panel · critical
init %s db file failed, err: %v
Error message
init %s db file failed, err: %v
What it means
Panic in LoadDBConnByPath when the SQLite db file does not exist (os.Stat error) and os.Create(fullPath) also fails. The dbName is interpolated, so the message names which database (core/agent/etc.) could not be initialized.
Source
Thrown at agent/utils/common/sqlite.go:23
"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 {
return nil, fmt.Errorf("init db dir failed, err: %v", err)
}
if _, err := os.Stat(fullPath); err != nil {
f, err := os.Create(fullPath)
if err != nil {View on GitHub (pinned to 5ac7c80881)
Solutions
- Create and permission the parent directory: mkdir -p <parent> && chown <agent user> <parent>, then restart the agent
- Confirm the volume is writable and not full: touch <parent>/.write-test; df -h
- As a last resort restore the default layout (reinstall 1Panel / 1pctl restore) so db paths are recreated
Example fix
# before docker logs 1panel: panic: init core db file failed, err: ... permission denied # after (on host) mkdir -p /opt/1panel/db && chown -R 1000:1000 /opt/1panel/db && docker restart 1panel
Defensive patterns
Strategy: validation
Validate before calling
sudo -u <agent-user> sh -c 'mkdir -p $(dirname /opt/1panel/db/core.db) && touch /opt/1panel/db/.wtest && rm /opt/1panel/db/.wtest' && echo ok
Prevention
- Smoke-test write access to the db directory as the service user before startup
- Prefer LoadDBConnByPathWithErr-style error returns in new code paths so callers can report instead of crashing
When it happens
Trigger: First boot or reset: os.Stat reports the file missing, then os.Create fails with e.g. 'permission denied' on the parent dir, 'read-only file system', or 'no such file or directory' because a deeper path component is absent.
Common situations: Parent directory removed after a failed cleanup; dir exists but without write permission for the agent user; db path on a read-only or full volume; container started with wrong volume mount.
Related errors
- init db dir failed, err: %v
- Fatal error config file: %s \n
- no enough parameter for location
- unexpected end of file while scanning a string, maybe an unc
- unexpected end of file while scanning a string, maybe an unc
AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15).
Data as JSON: /api/errors/00f7172a930e2f33.
Report an issue: GitHub.