Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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
#}
share|improve this answer
    
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 –  Olivier Dulac May 31 at 6:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.