2

Find below the logrotate configuration that I'm using

/usr/local/nagios/var/nagios.log {
    copytruncate
    daily
    rotate 7
    compress
    missingok
    size 100M
}

And I could notice that the status file /var/lib/logrotate.status is getting updated with current date daily but the log file is not getting rotated and it's growing in GB's until the disk get filled.

What would be the problem?

1 Answer 1

2

The problem is likely that Nagios is never killed/restarted so that it starts logging to a new log file. Here are a couple examples that show how you'd go about doing the postrotate action.

/var/log/nagios/nagios.log {
daily
rotate 180
compress
dateext
missingok
notifempty
sharedscripts
postrotate
        /sbin/service nagios reload > /dev/null 2>/dev/null || true
endscript
}

Or something more direct:

/var/log/nagios/nagios.log {
    missingok
    postrotate
        /bin/kill -HUP `cat /var/run/nagios.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

Letting Nagios do it

However in newer versions of Nagios it actually will rotate its own log files. The included logrotate configuration file even states as much.

On a Fedora 19 install of Nagios version 3.5.1-1:

$ more /etc/logrotate.d/nagios
# Important!  Nagios rotates its own logs.  Only enable this logrotate if you
# know what you are doing!

# For more information please see "log_rotate_method" in: 
# /etc/nagios/nagios.cfg

# ----- logrotate config -------------
#/var/log/nagios/*.log {
#       missingok
#       weekly
#       notifempty
#       nocompress
#       create 644 nagios nagios
#}
2
  • Yes, seems the problem. The OP should see a lot of ascii char 000 (Nul) (shown as : ^@ with cat -v, or in vi) at the beginning of the file. Why? Nagios is writing to the current position in the file, because its file decriptor points to that position. So linux happily do that and create a sparse file with zeroes before that "current position". (To avoid that, a program logging should always seek until the end, having opened the file in append mode (or with >> if it is a script) instead of the regular write (or '>' in a script). Thus it would seek until position 0 when the fil Commented May 31, 2014 at 6:37
  • 1
    Somewhat annoying with the nagios built-in rotation is that no mention is made that the files rotated out to the "archive" directory are never pruned. So you still need to add some sort of periodic log handling task even if logrotate is dis-recommended.
    – ericx
    Commented May 4, 2017 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .