How to enable logrotate

Hi, my logrotate seems never working.

I have a few customized logrotate configuration, one of them:

cat /etc/logrotate.d/mongo.conf

/etc/logrotate.d/

/app/intellisurf/logs/mongodb/mongod.log {
compress
copytruncate
daily
dateext
rotate 7
size 50M

manual testing is fine (> sudo logrotate -f /etc/logrotate.d/mongo.conf)

if I checked /var/lib/logrotate.status, all are long time ago:

cat /var/lib/logrotate.status
logrotate state – version 2
“/var/log/iscsiuio.log” 2017-5-12-11:0:0
“/var/log/apache2/deflate.log” 2017-5-12-11:0:0
“/var/log/samba/log.nmbd” 2017-5-12-11:0:0
“/var/log/news/news.crit” 2017-5-12-11:0:0
“/var/log/tomcat/catalina.out” 2017-5-14-11:0:1
“/app/intellisurf/log/mysql/mysqld.log” 2017-5-18-11:0:0
“/var/log/slpd.log” 2017-5-12-11:0:0

I didnot make any changes to default /etc/logrotate.conf:

cat /etc/logrotate.conf

see “man logrotate” for details

rotate log files weekly

weekly

I can see logrotate inside /etc/cron.daily:

ll /etc/cron.daily/
total 40
-rwxr-xr-x 1 root root 634 Sep 21 2014 logrotate
-rwxr-xr-x 1 root root 778 Oct 15 2016 mdadm
-rwxr-xr-x 1 root root 1414 Oct 26 2016 packagekit-background.cron
-rwxr–r-- 1 root root 948 Sep 27 2014 suse-clean_catman
-rwxr-xr-x 1 root root 1879 Oct 14 2016 suse.de-backup-rc.config
-rwxr-xr-x 1 root root 2059 Sep 11 2014 suse.de-backup-rpmdb
-rwxr-xr-x 1 root root 566 Sep 11 2014 suse.de-check-battery
-rwxr-xr-x 1 root root 371 Sep 11 2014 suse.de-cron-local
-rwxr-xr-x 1 root root 744 Oct 26 2016 suse.de-snapper
-rwxr–r-- 1 root root 1693 Sep 27 2014 suse-do_mandb

but I cannot see it in systemctl timer list and also cannot enable it (no such file or directory):

sudo systemctl list-timers -all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Tue 2017-10-17 12:05:01 SGT 19h left Mon 2017-10-16 12:05:01 SGT 4h 59min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2017-10-23 00:00:00 SGT 6 days left Mon 2017-10-16 11:50:21 SGT 5h 14min ago fstrim.timer fstrim.service

2 timers listed.

How to enable logrotate and verify it?

Thanks.

On 16/10/17 10:14, fastzhong wrote:
[color=blue]

Hi, my logrotate seems never working.

I have a few customized logrotate configuration, one of them:
[color=green]

cat /etc/logrotate.d/mongo.conf[/color]

/etc/logrotate.d/

/app/intellisurf/logs/mongodb/mongod.log {
compress
copytruncate
daily
dateext
rotate 7
size 50M[/color]

Presumably the above ends with a closing curly bracket (})?
[color=blue]

manual testing is fine (> sudo logrotate -f
/etc/logrotate.d/mongo.conf)[/color]

This statement would suggest there is a closing curly bracket so it must
have been missed when pasting.
[color=blue]

if I checked /var/lib/logrotate.status, all are long time ago:
[color=green]

cat /var/lib/logrotate.status[/color]
logrotate state – version 2
“/var/log/iscsiuio.log” 2017-5-12-11:0:0
“/var/log/apache2/deflate.log” 2017-5-12-11:0:0
“/var/log/samba/log.nmbd” 2017-5-12-11:0:0
“/var/log/news/news.crit” 2017-5-12-11:0:0
“/var/log/tomcat/catalina.out” 2017-5-14-11:0:1
“/app/intellisurf/log/mysql/mysqld.log” 2017-5-18-11:0:0
“/var/log/slpd.log” 2017-5-12-11:0:0

I didnot make any changes to default /etc/logrotate.conf:[color=green]

cat /etc/logrotate.conf[/color]

see “man logrotate” for details

rotate log files weekly

weekly

I can see logrotate inside /etc/cron.daily:
[color=green]

ll /etc/cron.daily/[/color]
total 40
-rwxr-xr-x 1 root root 634 Sep 21 2014 logrotate
-rwxr-xr-x 1 root root 778 Oct 15 2016 mdadm
-rwxr-xr-x 1 root root 1414 Oct 26 2016 packagekit-background.cron
-rwxr–r-- 1 root root 948 Sep 27 2014 suse-clean_catman
-rwxr-xr-x 1 root root 1879 Oct 14 2016 suse.de-backup-rc.config
-rwxr-xr-x 1 root root 2059 Sep 11 2014 suse.de-backup-rpmdb
-rwxr-xr-x 1 root root 566 Sep 11 2014 suse.de-check-battery
-rwxr-xr-x 1 root root 371 Sep 11 2014 suse.de-cron-local
-rwxr-xr-x 1 root root 744 Oct 26 2016 suse.de-snapper
-rwxr–r-- 1 root root 1693 Sep 27 2014 suse-do_mandb

but I cannot see it in systemctl timer list and also cannot enable it
(no such file or directory):
[color=green]

sudo systemctl list-timers -all[/color]
NEXT LEFT LAST
PASSED UNIT ACTIVATES
Tue 2017-10-17 12:05:01 SGT 19h left Mon 2017-10-16 12:05:01 SGT 4h
59min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2017-10-23 00:00:00 SGT 6 days left Mon 2017-10-16 11:50:21 SGT 5h
14min ago fstrim.timer fstrim.service

2 timers listed.

How to enable logrotate and verify it?[/color]

As recently posted in another recent logrotate thread[1] you need to
enable log rotation with “systemctl enable logrotate.timer” followed by
“systemctl start logrotate.timer”.

HTH.

[1] https://forums.suse.com/showthread.php?10067-Logrotate-in-etc-cron-daily

Simon
SUSE Knowledge Partner


If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below. Thanks.

Hi, actually i did try to do that, the problem is the logrotate.timer is missing from /etc/systemd/system/timers.target.wants. But thanks for answer, i just need to copy that file from somewhere.

Hi
The timer systemd service is in SP3, not SP2 it still uses the logrotate cronjob.

Do the other daily cron jobs run?

Have you configured the daily cron time via YaST /etc/sysconfig editor?

If you run the cronjob manually it runs?

Hi, malcolmlewis, you are right, the logrotate.timer is for SP3 not SP2, a temp cronjob is working.

ps -ef | grep cron
root 1773 1 0 Oct16 ? 00:00:00 /usr/sbin/cron -n

ll /etc/cron.daily/
total 40
-rwxr-xr-x 1 root root 634 Sep 21 2014 logrotate
-rwxr-xr-x 1 root root 778 Oct 15 2016 mdadm
-rwxr-xr-x 1 root root 1414 Oct 26 2016 packagekit-background.cron
-rwxr–r-- 1 root root 948 Sep 27 2014 suse-clean_catman
-rwxr-xr-x 1 root root 1879 Oct 14 2016 suse.de-backup-rc.config
-rwxr-xr-x 1 root root 2059 Sep 11 2014 suse.de-backup-rpmdb
-rwxr-xr-x 1 root root 566 Sep 11 2014 suse.de-check-battery
-rwxr-xr-x 1 root root 371 Sep 11 2014 suse.de-cron-local
-rwxr-xr-x 1 root root 744 Oct 26 2016 suse.de-snapper
-rwxr–r-- 1 root root 1693 Sep 27 2014 suse-do_mandb

I did not set the time for cron.daily to start, /etc/sysconfig/cron:

At which time cron.daily should start. Default is 15 minutes after booting

the system. Example setting would be “14:00”.

Due to the fact that cron script runs only every 15 minutes,

it will only run on xx:00, xx:15, xx:30, xx:45, not at the accurate time

you set.

DAILY_TIME=""

Thanks.

I did a test, and set DAILY_TIME=“12:10” and cron.daily seems being triggered:

ll /var/spool/cron/lastrun/

total 0
-rw-r–r-- 1 root root 0 Oct 17 12:15 cron.daily
-rw-r–r-- 1 root root 0 Oct 17 12:00 cron.hourly
-rw-r–r-- 1 root root 0 Sep 23 03:45 cron.monthly
-rw-r–r-- 1 root root 0 Oct 10 16:15 cron.weekly

but logrotate still seems not working:

cat /var/lib/logrotate.status

logrotate state – version 2
“/var/log/messages” 2017-10-11-16:15:1
“/var/log/apache2/error_log” 2017-5-12-11:0:0
“/var/log/firewall” 2017-5-12-11:0:0
“/var/log/xdm.errors” 2017-5-12-11:0:0
“/var/log/slpd.log” 2017-5-12-11:0:0
“/var/log/samba/log.winbindd” 2017-5-12-11:0:0
“/var/log/mail.err” 2017-5-12-11:0:0
“/var/log/speech-dispatcher/debug-epos-generic” 2017-5-12-11:0:0
“/var/log/vsftpd.log” 2017-5-12-11:0:0
“/var/log/zypp/history” 2017-5-12-11:0:0
“/var/log/zypp-refresh.log” 2017-5-12-11:0:0
“/var/log/NetworkManager” 2017-5-12-11:0:0
“/var/log/news/news.err” 2017-5-12-11:0:0
“/var/log/news/news.crit” 2017-5-12-11:0:0
“/var/log/btmp” 2017-5-12-11:0:0
“/var/log/snapper.log” 2017-5-12-11:0:0
“/var/log/speech-dispatcher/speech-dispatcher.log” 2017-5-12-11:0:0
“/var/log/zypper.log” 2017-5-12-11:0:0
“/var/log/iscsiuio.log” 2017-5-12-11:0:0
“/app/intellisurf/log/mongodb/mongod.log” 2017-5-18-11:0:0

Hi
Did you look at your config file and check the error user smflood indicated?

If you manually run;

/etc/cron.daily/logrotate

Any errors indicated?

Hi, there is no error but it does not work as expected:

sudo /etc/cron.daily/logrotate
compress_ext is /usr/bin/xz
compress_ext was changed to .xz

cat /etc/logrotate.d/mongo.conf

/etc/logrotate.d/

/app/intellisurf/logs/mongodb/mongod.log {
compress
copytruncate
daily
dateext
rotate 7
size 50M
}

ll /app/intellisurf/logs/mongodb
total 868
-rw-r–r-- 1 mongod mongod 22094 Oct 18 13:03 mongod.log
-rw-r–r-- 1 mongod mongod 862761 Sep 11 18:13 mongod.log.2017-09-11T10-13-00

btw, the logrotate problem happens on all machines with SuSE12 SP2.