Ubuntu – What schedules logrotate

cronlogrotate

I'm working on the program which creates a big log file.

I want to handle it with logrotate.

This is a configuration I put to /etc/logrotate.d/:

/var/log/myproject.log  {
 hourly
 maxsize 1
 rotate 6
 missingok
 notifempty
 compress
 nocreate
 copytruncate
 su www-data www-data 
}

(/var/log/myproject.log has owner www-data)

Commands

sudo logrotate -vf /etc/logrotate.conf

and

sudo logrotate -vf /etc/logrotate.d/myproject

rotate the log correctly.

However, after calling them /etc/cron.hourly is empty. Which means logrotate is not called hourly.

  1. Am I guaranteed to have logrotate script in /etc/cron.daily?

  2. Does the script check for frequency of update for log files. I.e. if I have logrotate script in /etc/cron.daily and for some log file X in /etc/logrotate.d/ I set weekly setting, will X be rotated daily or weekly?

  3. Can I just copy-paste /etc/cron.daily/logrotate to /etc/cron.hourly/? Can I cut-and-paste?

  4. Should I add 0anacron file to /etc/cron.hourly/?

  5. Should I do something else to enable hourly logging?

Best Answer

  1. No.

  2. From man logrotate:

    Each  configuration  file  can  set  global  options (local definitions
    override global ones, and later definitions override earlier ones)
    

    So, yes.

  3. Again, from the manpage:

    hourly Log files are rotated every hour. Note that usually logrotate is
           configured  to  be  run  by  cron daily. You have to change this
           configuration and run logrotate hourly  to  be  able  to  really
           rotate logs hourly.
    

    So, yes, you should move the script. Inspecting the cron.daily script in my system, I think moving it should work fine.

Related Question