{"record":{"id":"18626ee129ff6397","repo":"benbjohnson/litestream","slug":"start-directory-monitor-for-s-w","errorCode":null,"errorMessage":"start directory monitor for %s: %w","messagePattern":"start directory monitor for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/replicate.go","lineNumber":321,"sourceCode":"\t\tc.Server.SocketPath = c.Config.Socket.Path\n\t\tc.Server.SocketPerms = c.Config.Socket.Permissions\n\t\tc.Server.PathExpander = expand\n\t\tc.Server.Version = Version\n\t\tif err := c.Server.Start(); err != nil {\n\t\t\tslog.Warn(\"failed to start control server\", \"error\", err)\n\t\t}\n\t}\n\n\tfor _, entry := range watchables {\n\t\tmonitor, err := NewDirectoryMonitor(ctx, c.Store, entry.config, entry.dbs)\n\t\tif err != nil {\n\t\t\tfor _, m := range c.directoryMonitors {\n\t\t\t\tm.Close()\n\t\t\t}\n\t\t\tif closeErr := c.Store.Close(ctx); closeErr != nil {\n\t\t\t\tslog.Error(\"failed to close store after monitor failure\", \"error\", closeErr)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"start directory monitor for %s: %w\", entry.config.Dir, err)\n\t\t}\n\t\tc.directoryMonitors = append(c.directoryMonitors, monitor)\n\t}\n\n\t// Notify user that initialization is done.\n\tfor _, db := range c.Store.DBs() {\n\t\tr := db.Replica\n\t\tslog.Info(\"initialized db\", \"path\", db.Path())\n\t\tslogWith := slog.With(\"type\", r.Client.Type(), \"sync-interval\", r.SyncInterval)\n\t\tswitch client := r.Client.(type) {\n\t\tcase *file.ReplicaClient:\n\t\t\tslogWith.Info(\"replicating to\", \"path\", client.Path())\n\t\tcase *s3.ReplicaClient:\n\t\t\tslogWith.Info(\"replicating to\", \"bucket\", client.Bucket, \"path\", client.Path, \"region\", client.Region, \"endpoint\", client.Endpoint)\n\t\tcase *gs.ReplicaClient:\n\t\t\tslogWith.Info(\"replicating to\", \"bucket\", client.Bucket, \"path\", client.Path)\n\t\tcase *abs.ReplicaClient:\n\t\t\tslogWith.Info(\"replicating to\", \"bucket\", client.Bucket, \"path\", client.Path, \"endpoint\", client.Endpoint)","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/replicate.go#L303-L339","documentation":"Directory monitors watch configured directories for new SQLite databases and register them with the store. When starting a monitor fails (e.g. the directory does not exist or cannot be watched), Run closes already-started monitors and the store, then returns this error naming the offending directory.","triggerScenarios":"Config contains a directory monitor entry (`dir:` style config); the monitored path doesn't exist, isn't readable, or the filesystem watcher cannot be initialized. `monitor.Start(ctx)` returns err at line ~321 of replicate.go.","commonSituations":"Typo in monitored directory path, directory created only after litestream starts, containers where the volume isn't mounted yet, inotify limits exhausted on Linux.","solutions":["Check the directory path in the error exists and is readable before starting litestream","Fix the config entry for the directory monitor (remove or correct the path)","Ensure the volume/directory is mounted in containerized deployments before startup","Raise fs.inotify.max_user_watches/max_user_instances if watcher limits are the cause"],"exampleFix":"// before (config)\nmonitor:\n  - dir: /data/dbs\n// after\n# verify path exists\nmkdir -p /data/dbs && litestream replicate -config litestream.yml","handlingStrategy":"validation","validationCode":"# ensure all monitored dirs exist and are readable before start\nfor d in $(yq '.monitor[].dir' litestream.yml); do\n  [ -d \"$d\" ] && [ -r \"$d\" ] || { echo \"bad monitor dir: $d\" >&2; exit 1; }\ndone","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(ctx); err != nil {\n    if strings.Contains(err.Error(), \"start directory monitor\") {\n        // extract dir from message, alert on config/volume problem\n    }\n    return err\n}","preventionTips":["Create monitored directories before litestream starts (init containers / entrypoint scripts)","Mount volumes before launching litestream in containers","Check fs.inotify limits (max_user_watches) on hosts with many directories","Keep monitor dir entries in sync with actual filesystem layout"],"tags":["filesystem","monitor","startup"],"backgroundTag":"directory-not-found","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}