fluent/fluentd · error · Fluent::ConfigError

Cannot access pid file: #{pid_path}

Error message

Cannot access pid file: #{pid_path}

What it means

When fluentd daemonizes (--daemon PIDFILE), check_pidfile runs before spawning: an existing pidfile must be both readable and writable by the current user, otherwise startup aborts with this ConfigError. Fluentd needs read access to check whether the recorded pid is alive and write access to replace it with the new daemon pid. The check deliberately fails closed so two daemons never race on one pidfile.

Source

Thrown at lib/fluent/daemonizer.rb:56

      rescue NotImplementedError
        daemonize_with_spawn(pid_fullpath, args)
      end
    end

    private

    def daemonize_with_spawn(pid_fullpath, args)
      pid = Process.spawn(*['fluentd'].concat(args))

      File.write(pid_fullpath, pid.to_s)

      pid
    end

    def check_pidfile(pid_path)
      if File.exist?(pid_path)
        if !File.readable?(pid_path) || !File.writable?(pid_path)
          raise Fluent::ConfigError, "Cannot access pid file: #{pid_path}"
        end

        pid =
          begin
            Integer(File.read(pid_path), 10)
          rescue TypeError, ArgumentError
            return # ignore
          end

        begin
          Process.kill(0, pid)
          raise Fluent::ConfigError, "pid(#{pid}) is running"
        rescue Errno::EPERM
          raise Fluent::ConfigError, "pid(#{pid}) is running"
        rescue Errno::ESRCH
        end
      else
        unless File.writable?(File.dirname(pid_path))

View on GitHub (pinned to dd45c6e18d)

Solutions

  1. Verify no fluentd is running for that pidfile (ps -p $(cat /path/to/fluentd.pid)), then remove the stale pidfile
  2. chown the pidfile to the daemon user or chmod 664 so the current user can read and write it
  3. Run the daemon under the same user that owns the pidfile
  4. Use a per-instance pidfile path under the daemon user's own runtime directory (e.g. systemd RuntimeDirectory=fluentd)

Example fix

# before
$ sudo fluentd --daemon /var/run/fluentd.pid ...
$ fluentd --daemon /var/run/fluentd.pid ...   # fails: not writable

# after
$ ps -p $(cat /var/run/fluentd.pid) || sudo rm /var/run/fluentd.pid
$ sudo chown fluent:fluent /var/run/fluentd.pid 2>/dev/null || true
$ fluentd --daemon /var/run/fluentd.pid ...
Defensive patterns

Strategy: validation

Validate before calling

pidfile = '/var/run/fluentd.pid'
if File.exist?(pidfile)
  abort "pidfile not readable/writable" unless File.readable?(pidfile) && File.writable?(pidfile)
end

Prevention

When it happens

Trigger: Starting fluentd --daemon /var/run/fluentd.pid as the fluent user when a previous root-run fluentd left a 0600 root-owned pidfile; pidfile created by a different user; ACLs denying write on the file.

Common situations: Switching the daemon user between runs (root to non-root); leftover pidfile from a crashed/killed root process; container images baked with a root-owned pidfile.

Related errors


AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21). Data as JSON: /api/errors/022c274db89c78e3. Report an issue: GitHub.