{"record":{"id":"6779f68e5c9c23f4","repo":"fluent/fluentd","slug":"cannot-access-directory-for-pid-file-file-dirna","errorCode":null,"errorMessage":"Cannot access directory for pid file: #{File.dirname(pid_path)}","messagePattern":"Cannot access directory for pid file: #(.+?)","errorType":"exception","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/daemonizer.rb","lineNumber":75,"sourceCode":"        end\n\n        pid =\n          begin\n            Integer(File.read(pid_path), 10)\n          rescue TypeError, ArgumentError\n            return # ignore\n          end\n\n        begin\n          Process.kill(0, pid)\n          raise Fluent::ConfigError, \"pid(#{pid}) is running\"\n        rescue Errno::EPERM\n          raise Fluent::ConfigError, \"pid(#{pid}) is running\"\n        rescue Errno::ESRCH\n        end\n      else\n        unless File.writable?(File.dirname(pid_path))\n          raise Fluent::ConfigError, \"Cannot access directory for pid file: #{File.dirname(pid_path)}\"\n        end\n      end\n    end\n\n    def install_at_exit_handlers(pidfile)\n      at_exit do\n        if File.exist?(pidfile)\n          File.delete(pidfile)\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":57,"sourceCodeEnd":89,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/daemonizer.rb#L57-L89","documentation":"When the pidfile does not exist yet, fluentd must create it, so it checks that the parent directory is writable (File.writable?(File.dirname(pid_path))) and aborts with this ConfigError when it is not. This covers a missing directory, a read-only mount, or a directory owned by another user. It fires before daemonize, i.e. at option-processing/startup time.","triggerScenarios":"fluentd --daemon /var/run/fluentd/fluentd.pid when /var/run/fluentd does not exist or is root-owned 755 and fluentd runs as non-root; pidfile under /run (tmpfs wiped at boot); read-only filesystem mounts.","commonSituations":"Non-root daemon pointed at /var/run or /run paths; reboot clearing tmpfs directories not recreated by an init script; containers without the runtime dir baked in.","solutions":["Create the directory and hand it to the daemon user: mkdir -p /var/run/fluentd && chown fluent:fluent /var/run/fluentd","With systemd, use RuntimeDirectory=fluentd so the unit creates /run/fluentd with correct ownership each boot","Point --daemon at a path in a writable directory (e.g. /var/lib/fluentd or the user's runtime dir)","For quick tests, use a pidfile under /tmp or the current directory"],"exampleFix":"# before\n$ fluentd --daemon /var/run/fluentd/fluentd.pid ...  # dir missing/root-owned\n\n# after\n$ sudo mkdir -p /var/run/fluentd && sudo chown fluent:fluent /var/run/fluentd\n$ fluentd --daemon /var/run/fluentd/fluentd.pid ...","handlingStrategy":"validation","validationCode":"dir = File.dirname(pid_path)\nFileUtils.mkdir_p(dir) unless Dir.exist?(dir)\nabort \"pid dir not writable: #{dir}\" unless File.writable?(dir)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["With systemd use RuntimeDirectory=fluentd so /run/fluentd is recreated per boot","Pre-create and chown pid directories in your start script","Avoid /run and /var/run for non-root daemons without a dedicated runtime dir"],"tags":["fluentd","daemon","pidfile","permissions","filesystem"],"backgroundTag":"pid-file-permission-denied","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}