cdn-logs: Hourly cronjob for logrotate not firing
ewdurbin opened this issue · 2 comments
Our hourly logrotate cron job is not working on Ubuntu 20.04
psf-salt/salt/cdn-logs/init.sls
Lines 17 to 19 in d6c01b1
This is due to logrotate preferring the systemd timer (see first if
clause below):
ee@cdn-logs:/var/log/fastly$ ls -alhtr /etc/cron.hourly/logrotate
lrwxrwxrwx 1 root root 25 Jan 3 15:38 /etc/cron.hourly/logrotate -> /etc/cron.daily/logrotate
ee@cdn-logs:/var/log/fastly$ cat /etc/cron.daily/logrotate
#!/bin/sh
# skip in favour of systemd timer
if [ -d /run/systemd/system ]; then
exit 0
fi
# this cronjob persists removals (but not purges)
if [ ! -x /usr/sbin/logrotate ]; then
exit 0
fi
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit $EXITVALUE
We should update our configuration to change the systemd timer from daily to hourly on this host for logrotate.
Timer is currently configured as follows by default on installation of logrotate:
ee@cdn-logs:/var/log/fastly$ cat /etc/systemd/system/timers.target.wants/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
I'm not positive what the best way to go about editing the timer is, but it may be as "simple" as overriding the file with salt and calling systemctl daemon-reload
as we do for services.
References:
- Systemd Timers from ArchWiki: https://wiki.archlinux.org/title/Systemd/Timers
You may be able to use the ini file state: https://docs.saltproject.io/en/latest/ref/states/all/salt.states.ini_manage.html#salt.states.ini_manage.options_present to edit the value without creating a full template.