27

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?

2
  • 3
    Tip for question 1: look at the output of grep -r logrotate /etc/cron*
    – guntbert
    Nov 28, 2014 at 21:53
  • @guntbert I've said it before and I'll say it again. You're a saint and a hero. Aug 24, 2016 at 14:18

1 Answer 1

13
  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.

You must log in to answer this question.

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