{"record":{"id":"4fef8f103da79a67","repo":"fluent/fluentd","slug":"failed-to-create-root-directory-root-dir-e-i","errorCode":null,"errorMessage":"failed to create root directory:#{root_dir}, #{e.inspect}","messagePattern":"failed to create root directory:#(.+?), #(.+?)","errorType":"exception","errorClass":"Fluent::InvalidRootDirectory","httpStatus":null,"severity":"critical","filePath":"lib/fluent/supervisor.rb","lineNumber":719,"sourceCode":"      if @system_config.workers < 1\n        raise Fluent::ConfigError, \"invalid number of workers (must be > 0):#{@system_config.workers}\"\n      end\n\n      if Fluent.windows? && @system_config.with_source_only\n        raise Fluent::ConfigError, \"with-source-only is not supported on Windows\"\n      end\n\n      root_dir = @system_config.root_dir\n      if root_dir\n        if File.exist?(root_dir)\n          unless Dir.exist?(root_dir)\n            raise Fluent::InvalidRootDirectory, \"non directory entry exists:#{root_dir}\"\n          end\n        else\n          begin\n            FileUtils.mkdir_p(root_dir, mode: @system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION)\n          rescue => e\n            raise Fluent::InvalidRootDirectory, \"failed to create root directory:#{root_dir}, #{e.inspect}\"\n          end\n        end\n      end\n\n      begin\n        ServerEngine::Privilege.change(@chuser, @chgroup)\n        MessagePackFactory.init(enable_time_support: @system_config.enable_msgpack_time_support)\n        Fluent::Engine.init(@system_config, supervisor_mode: true, start_in_parallel: ENV.key?(\"FLUENT_RUNNING_IN_PARALLEL_WITH_OLD\"))\n        Fluent::Engine.run_configure(@conf, dry_run: dry_run)\n      rescue Fluent::ConfigError => e\n        $log.error 'config error', file: @config_path, error: e\n        $log.debug_backtrace\n        exit!(1)\n      rescue ScriptError => e # LoadError, NotImplementedError, SyntaxError\n        if e.respond_to?(:path)\n          $log.error e.message, path: e.path, error: e\n        else\n          $log.error e.message, error: e","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/supervisor.rb#L701-L737","documentation":"Fluentd raises Fluent::InvalidRootDirectory during startup when the <system> root_dir path does not exist and FileUtils.mkdir_p fails to create it (lib/fluent/supervisor.rb:719). The nested e.inspect in the message carries the underlying filesystem error, such as Errno::EACCES or Errno::ENOSPC. This happens before any plugin starts, so the whole fluentd process aborts during configuration/boot.","triggerScenarios":"Setting <system> root_dir /path/to/dir where the parent path is not writable by the fluentd user, the disk or inode quota is exhausted, a symlink in the path is broken, or the path crosses a read-only mount. Also triggered when root_dir points somewhere SELinux denies creation for the fluentd process context.","commonSituations":"Running fluentd as a low-privileged user while root_dir points under /var/log/fluent or a Docker volume owned by root; deploying to Kubernetes with an emptyDir/volumeMount whose ownership does not match the container UID; SELinux/AppArmor denying writes; full disk filling /tmp.","solutions":["Check the underlying error in the message (e.inspect) — Errno::EACCES means permissions, Errno::ENOSPC means disk full","If permission denied: chown or chmod the parent directory so the fluentd user can create it (e.g. install -d -o fluent -g fluent /var/log/fluent)","If running in a container, ensure the volume mounted at root_dir is writable by the container user (fsGroup / runAsUser in Kubernetes, or chown in an entrypoint)","Pre-create the directory yourself before starting fluentd so mkdir_p is never called","For SELinux denials, set the correct context (restorecon) or adjust the policy for the fluentd process"],"exampleFix":"# before\n<system>\n  root_dir /var/log/fluent/buffer   # owned by root, fluentd runs as 'fluent'\n</system>\n\n# after (option 1: pre-create with correct ownership)\n#   sudo install -d -o fluent -g fluent /var/log/fluent/buffer\n# after (option 2: point root_dir somewhere writable)\n<system>\n  root_dir /home/fluent/spool\n</system>","handlingStrategy":"validation","validationCode":"require 'fileutils'\n\nroot_dir = '/var/log/fluent'\n# pre-flight check mirroring supervisor.rb logic\nif File.exist?(root_dir)\n  abort \"#{root_dir} exists but is not a directory\" unless Dir.exist?(root_dir)\nelse\n  begin\n    FileUtils.mkdir_p(root_dir)\n  rescue => e\n    abort \"cannot create #{root_dir}: #{e.class} #{e.message} — check permissions/disk\"\n  end\nend\n# also verify writability of the final directory\nabort \"#{root_dir} not writable\" unless File.writable?(root_dir)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create root_dir with correct ownership in your provisioning (install -d -o fluent -g fluent)","In containers, chown the volume in the entrypoint or set Kubernetes fsGroup to match the fluentd user","Monitor disk free space and inodes on the root_dir filesystem","Run fluentd --dry-run after config changes to fail before production restart"],"tags":["fluentd","filesystem","permissions","startup","root-dir","mkdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}