-1

I use ubuntu 14.04 I try to run logrotate each 10min and remove all logs files bigger then 2MB, I try a lot solution but nothing not work, my logrotate run just 1 per day, I try solution with moved logrotate from cron.daily to cron.hourly but not work, I try other solution and do next:

create file logrotate:

*/10  *  *  *  *   root /usr/sbin/logrotate /etc/logrotate.conf

and add in:

/etc/cron.d

this is my /etc/logrotate.d/apache2:

/var/log/apache2/*.log /var/log/apache2/domains/*log {
    weekly
    missingok
    rotate 10
    maxsize 2M
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
            /etc/init.d/apache2 reload > /dev/null || true
            [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
    endscript
    prerotate
            if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                    run-parts /etc/logrotate.d/httpd-prerotate; \
            fi; \
    endscript
}
nikola99
  • 101
  • 8
  • Work your way through the duplicate above, it **will** ( _almost certainly_) **help you solve you problem**. If it doesn't help, it will help you gather information that will help us help you. – user9517 Jan 05 '16 at 10:38
  • i check and cron running – nikola99 Jan 05 '16 at 10:42
  • 1
    There is a lot more to the linked Q&A than just checking that cron is running. Please spend some time working through it, it will help you solve your problem. – user9517 Jan 05 '16 at 10:44

2 Answers2

1

You should remove the weekly keyword from you configuration if size is the only criterium for rotating your log files.

man 8 logrotate

weekly
Log files are rotated if the current weekday is less then the weekday of the last rotation or if more then a week has passed since the last rotation. This is normally the same as rotating logs on the first day of the week, but it works better if logrotate is not run every night.

But rather than potentially having your apache webserver getting restarted every 10 minutes, consider using rotatelogs which can be configured to only keep a small number of limited sized logs:

CustomLog "|bin/rotatelogs -n 10 /var/log/access_log 2M" common
HBruijn
  • 72,524
  • 21
  • 127
  • 192
0

Logrotate is supposed to run once a day. That's why it located in /etc/cron.daily/logrotate
If you want to run logrotate more often, you need to remove /etc/cron.daily/logrotate and add logrotate record in crontab manually.

user1700494
  • 1,642
  • 2
  • 11
  • 20