# How to enable logrotate

**URL:** <https://forums.suse.com/t/how-to-enable-logrotate/30439>\
**Category:** SLES Configure-Administer\
**Created:** [October 16, 2017, 12:04pm UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439 "2017-10-16T12:04:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fastzhong](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fastzhong](https://forums.suse.com/u/fastzhong)\
**Post date:** [October 16, 2017, 12:04pm UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/1 "2017-10-16T12:04:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![smflood](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/smflood/32/10576_2.png) [@smflood](https://forums.suse.com/u/smflood)\
**Post date:** [October 16, 2017, 4:12pm UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/2 "2017-10-16T16:12:53Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![fastzhong](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fastzhong](https://forums.suse.com/u/fastzhong)\
**Post date:** [October 17, 2017, 5:29am UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/3 "2017-10-17T05:29:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![malcolmlewis](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/malcolmlewis/32/11375_2.png) [@malcolmlewis](https://forums.suse.com/u/malcolmlewis)\
**Post date:** [October 17, 2017, 5:58am UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/4 "2017-10-17T05:58:55Z")

</div>

> [@fastzhong;39898](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![fastzhong](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fastzhong](https://forums.suse.com/u/fastzhong)\
**Post date:** [October 17, 2017, 6:44am UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/5 "2017-10-17T06:44:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fastzhong](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fastzhong](https://forums.suse.com/u/fastzhong)\
**Post date:** [October 17, 2017, 7:38am UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/6 "2017-10-17T07:38:40Z")

</div>

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  
…

---

<div class="post-metadata">

**Author:** ![malcolmlewis](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/malcolmlewis/32/11375_2.png) [@malcolmlewis](https://forums.suse.com/u/malcolmlewis)\
**Post date:** [October 17, 2017, 5:44pm UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/7 "2017-10-17T17:44:33Z")

</div>

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

If you manually run;

```auto
/etc/cron.daily/logrotate
```

Any errors indicated?

---

<div class="post-metadata">

**Author:** ![fastzhong](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fastzhong](https://forums.suse.com/u/fastzhong)\
**Post date:** [October 19, 2017, 6:50am UTC](https://forums.suse.com/t/how-to-enable-logrotate/30439/8 "2017-10-19T06:50:30Z")

</div>

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.
