Logrotate in /etc/cron.daily

Hello everyone,

after upgrading from SLES12 SP2 to SP3 the logrotation from /etc/logroate.d/ via cronjob doesn’t working anymore.
So I found out, that the logrotate-file in /etc/cron.daily/ has gone away.

Is this a feature or a bug? :confused:

Is there a new way to rotate the logs?

Best Regards
Christian

[QUOTE=christianmolecki;39820]Hello everyone,

after upgrading from SLES12 SP2 to SP3 the logrotation from /etc/logroate.d/ via cronjob doesn’t working anymore.
So I found out, that the logrotate-file in /etc/cron.daily/ has gone away.

Is this a feature or a bug? :confused:

Is there a new way to rotate the logs?

Best Regards
Christian[/QUOTE]
Hi
A feature… things moving to systemd…

systemctl status logrotate.service

You should see;

Process: [PID] ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=0/SUCCESS)

Thanks for your answer.

So, logrotate.servcice is deactivated.
If I activate it, when will the logrotate-command execute?

Hi
Yes it will, you can check the time it last ran from the status output, eg;

systemctl status logrotate.service 

● logrotate.service - Rotate log files
   Loaded: loaded (/usr/lib/systemd/system/logrotate.service; static; vendor preset: disabled)
   Active: inactive (dead) since Fri 2017-10-06 06:03:04 CDT; 5min ago

systemctl start logrotate.service

systemctl status logrotate.service 

● logrotate.service - Rotate log files
   Loaded: loaded (/usr/lib/systemd/system/logrotate.service; static; vendor preset: disabled)
   Active: inactive (dead) since Fri 2017-10-06 07:04:21 CDT; 7s ago

Hello malcolmlewis,

I made a cron which execute systemctl start logrotate.service

Best Regards.

[QUOTE=christianmolecki;39849]Hello malcolmlewis,

I made a cron which execute systemctl start logrotate.service

Best Regards.[/QUOTE]
Hi
But it is done automatically by systemd timers, no need for a cron job?

ls -la /etc/systemd/system/timers.target.wants/
total 8
drwxr-xr-x 1 root root   54 Sep 24 19:11 .
drwxr-xr-x 1 root root 1180 Sep 24 20:21 ..
lrwxrwxrwx 1 root root   36 Sep 24 19:11 fstrim.timer -> /usr/lib/systemd/system/fstrim.timer
lrwxrwxrwx 1 root root   39 Sep 24 19:11 logrotate.timer -> /usr/lib/systemd/system/logrotate.timer

cat /usr/lib/systemd/system/logrotate.timer
[Unit]
Description=Daily rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true

[Install]
WantedBy=timers.target

Hi,

at both places are no logrotate.timer

[CODE]/etc/systemd/system/timers.target.wants # l
total 8
drwxr-xr-x 2 root root 4096 Mar 30 2017 ./
drwxr-xr-x 12 root root 4096 Aug 31 13:56 …/
lrwxrwxrwx 1 root root 36 Mar 30 2017 fstrim.timer → /usr/lib/systemd/system/fstrim.timer

/usr/lib/systemd # l
total 8832
drwxr-xr-x 15 root root 4096 Jun 27 10:59 ./
drwxr-xr-x 96 root root 36864 Oct 3 11:07 …/
drwxr-xr-x 3 root root 4096 Aug 31 13:56 boot/
drwxr-xr-x 2 root root 4096 Sep 18 10:28 catalog/
-rwxr-xr-x 1 root root 3445 Aug 31 13:56 fix-machines-subvol-for-rollbacks.sh*
-rw-r–r-- 1 root root 9551 Aug 31 13:56 import-pubring.gpg
drwxr-xr-x 2 root root 4096 Sep 18 10:28 network/
drwxr-xr-x 2 root root 4096 Aug 31 13:56 ntp-units.d/
drwxr-xr-x 2 root root 4096 Oct 3 11:07 scripts/
drwxr-xr-x 32 root root 20480 Oct 9 08:01 system/
drwxr-xr-x 2 root root 4096 Oct 3 11:05 system-generators/
drwxr-xr-x 2 root root 4096 Oct 3 11:08 system-preset/
drwxr-xr-x 2 root root 4096 Oct 3 11:07 system-shutdown/
drwxr-xr-x 2 root root 4096 Oct 3 11:05 system-sleep/
-rwxr-xr-x 1 root root 1589144 Aug 31 13:56 systemd*
-rwxr-xr-x 1 root root 18480 Aug 31 13:56 systemd-ac-power*
-rwxr-xr-x 1 root root 67792 Aug 31 13:56 systemd-activate*
-rwxr-xr-x 1 root root 117104 Aug 31 13:56 systemd-backlight*
-rwxr-xr-x 1 root root 67952 Aug 31 13:56 systemd-binfmt*
-rwxr-xr-x 1 root root 121264 Aug 31 13:56 systemd-bootchart*
-rwxr-xr-x 1 root root 388088 Aug 31 13:56 systemd-bus-proxyd*
-rwxr-xr-x 1 root root 39120 Aug 31 13:56 systemd-cgroups-agent*
-rwxr-xr-x 1 root root 121232 Aug 31 13:56 systemd-coredump*
-rwxr-xr-x 1 root root 113016 Aug 31 13:56 systemd-cryptsetup*
-rwxr-xr-x 1 root root 141680 Aug 31 13:56 systemd-export*
-rwxr-xr-x 1 root root 339632 Aug 31 13:56 systemd-fsck*
-rwxr-xr-x 1 root root 43216 Aug 31 13:56 systemd-hibernate-resume*
-rwxr-xr-x 1 root root 371696 Aug 31 13:56 systemd-hostnamed*
-rwxr-xr-x 1 root root 158064 Aug 31 13:56 systemd-import*
-rwxr-xr-x 1 root root 392880 Aug 31 13:56 systemd-importd*
-rwxr-xr-x 1 root root 310256 Aug 31 13:56 systemd-initctl*
-rwxr-xr-x 1 root root 354672 Aug 31 13:56 systemd-journald*
-rwxr-xr-x 1 root root 375792 Aug 31 13:56 systemd-localed*
-rwxr-xr-x 1 root root 650928 Aug 31 13:56 systemd-logind*
-rwxr-xr-x 1 root root 528048 Aug 31 13:56 systemd-machined*
-rwxr-xr-x 1 root root 67952 Aug 31 13:56 systemd-modules-load*
-rwxr-xr-x 1 root root 239984 Aug 31 13:56 systemd-pull*
-rwxr-xr-x 1 root root 43288 Aug 31 13:56 systemd-quotacheck*
-rwxr-xr-x 1 root root 47312 Aug 31 13:56 systemd-random-seed*
-rwxr-xr-x 1 root root 67952 Aug 31 13:56 systemd-remount-fs*
-rwxr-xr-x 1 root root 39120 Aug 31 13:56 systemd-reply-password*
-rwxr-xr-x 1 root root 117104 Aug 31 13:56 systemd-rfkill*
-rwxr-xr-x 1 root root 170352 Aug 31 13:56 systemd-shutdown*
-rwxr-xr-x 1 root root 92520 Aug 31 13:56 systemd-sleep*
-rwxr-xr-x 1 root root 108912 Aug 31 13:56 systemd-socket-proxyd*
-rwxr-xr-x 1 root root 72048 Aug 31 13:56 systemd-sysctl*
-rwxr-xr-x 1 root root 987 Aug 31 13:56 systemd-sysv-install*
-rwxr-xr-x 1 root root 372432 Aug 31 13:56 systemd-timedated*
-rwxr-xr-x 1 root root 162160 Aug 31 13:56 systemd-timesyncd*
-rwxr-xr-x 1 root root 481664 Aug 31 13:56 systemd-udevd*
-rwxr-xr-x 1 root root 47312 Aug 31 13:56 systemd-update-done*
-rwxr-xr-x 1 root root 314360 Aug 31 13:56 systemd-update-utmp*
-rwxr-xr-x 1 root root 43216 Aug 31 13:56 systemd-user-sessions*
-rwxr-xr-x 1 root root 59680 Aug 31 13:56 systemd-vconsole-setup*
drwxr-xr-x 2 root root 4096 Jun 27 10:59 user/
drwxr-xr-x 2 root root 4096 Sep 18 10:28 user-generators/
drwxr-xr-x 2 root root 4096 Jun 27 10:59 user-preset/
[/CODE]

Hi
Is the logrotate package installed?


Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
openSUSE Leap 42.2|GNOME 3.20.2|4.4.87-18.29-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

yes

[CODE]zypper search logrotate
Refreshing service ‘SUSE_Linux_Enterprise_Server_12_SP3_x86_64’.
Refreshing service ‘SUSE_Linux_Enterprise_Software_Development_Kit_12_SP3_x86_64’.
Refreshing service ‘Web_and_Scripting_Module_12_x86_64’.
Loading repository data…
Reading installed packages…

S | Name | Summary | Type
–±----------±----------------------------------------------------±-------
i | logrotate | Rotate, compress, remove, and mail system log files | package
[/CODE]

Hi
Hmmm, look in /usr/lib/systemd/system/ the file logrotate.timer should be there, if not force the re-install of logrotate and check again and for the softlink down in /etc/systemd/system/timers.target.wants/

Else manually create the link;

ln -s /usr/lib/systemd/system/logrotate.timer /etc/systemd/system/timers.target.wants/logrotate.timer
systemctl daemon-reload

[QUOTE=malcolmlewis;39858]Hi
Hmmm, look in /usr/lib/systemd/system/ the file logrotate.timer should be there, if not force the re-install of logrotate and check again and for the softlink down in /etc/systemd/system/timers.target.wants/

Else manually create the link;

ln -s /usr/lib/systemd/system/logrotate.timer /etc/systemd/system/timers.target.wants/logrotate.timer systemctl daemon-reload [/QUOTE]

The timer has to be enabled. This creates the link!

/root>systemctl enable logrotate.timer 
Created symlink from /etc/systemd/system/timers.target.wants/logrotate.timer to /usr/lib/systemd/system/logrotate.timer.

After enabling the timer, the link exists.

OnCalendar=daily AccuracySec=12h

means logrotation everyday at 12:00 and 24:00?

Hi
I would imagine it’s daily from last boot time…

systemctl status logrotate.timer
● logrotate.timer - Daily rotation of log files
Loaded: loaded (/usr/lib/systemd/system/logrotate.timer; enabled;
vendor preset: enabled) Active: active (waiting) since Tue 2017-10-17
09:26:54 CDT; 13min ago Docs: man:logrotate(8)
man:logrotate.conf(5)

Oct 17 09:26:54 oscar systemd[1]: Started Daily rotation of log files.


Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
openSUSE Leap 42.2|GNOME 3.20.2|4.4.87-18.29-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

I want to logrotate the apache2 logfiles, daily at 24:00.
How can I do that with the systemd logrotate?

[QUOTE=christianmolecki;39928]I want to logrotate the apache2 logfiles, daily at 24:00.
How can I do that with the systemd logrotate?[/QUOTE]
Hi
I would look at disabling the timer and then copy /usr/lib/systemd/system/logrotate.timer to /etc/systemd/system/ then edit OnCalander to equal --* 00:00:00 and enable/start/status the service, it should be pointing at your timer service and not the systemd one.

If you look at man systemd.time at the end there are lots of configuration options, eg add UTC if your wanting it to be at 00:00:00 UTC

Hello,

systemctl enable logrotate.service systemctl enable logrotate.timer systemctl start logrotate.timer

Now, the logrotate will execute on 24:00/00:00.

Thanks for your help!