replace cron job with systemd timer unit

... and enable the timer unit if the cron job was enabled

Resolves: #1502085
Resolves: #1655153

Closes #1
This commit is contained in:
Alejandro Domínguez Muñoz 2018-11-21 00:35:34 +00:00 committed by Kamil Dudka
parent 6fe90d379f
commit dadc24ae1f

View File

@ -15,7 +15,10 @@ BuildRequires: libacl-devel
BuildRequires: libselinux-devel BuildRequires: libselinux-devel
BuildRequires: make BuildRequires: make
BuildRequires: popt-devel BuildRequires: popt-devel
BuildRequires: systemd-rpm-macros
Requires: coreutils Requires: coreutils
Requires(post): systemd
Requires(preun): systemd
# document the --version option in the logrotate(8) man page (#1611498) # document the --version option in the logrotate(8) man page (#1611498)
Patch1: 0001-logrotate-3.14.0-man-version.patch Patch1: 0001-logrotate-3.14.0-man-version.patch
@ -28,8 +31,7 @@ The logrotate utility is designed to simplify the administration of
log files on a system which generates a lot of log files. Logrotate log files on a system which generates a lot of log files. Logrotate
allows for the automatic rotation compression, removal and mailing of allows for the automatic rotation compression, removal and mailing of
log files. Logrotate can be set to handle a log file daily, weekly, log files. Logrotate can be set to handle a log file daily, weekly,
monthly or when the log file gets to a certain size. Normally, monthly or when the log file gets to a certain size.
logrotate runs as a daily cron job.
Install the logrotate package if you need a utility to deal with the Install the logrotate package if you need a utility to deal with the
log files on your system. log files on your system.
@ -70,12 +72,12 @@ make %{?_smp_mflags} -C build check
%make_install -C build %make_install -C build
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/cron.daily mkdir -p $RPM_BUILD_ROOT%{_unitdir}
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/lib/logrotate mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/lib/logrotate
install -p -m 644 examples/logrotate-default $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.conf install -p -m 644 examples/logrotate-default $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.conf
install -p -m 644 examples/{b,w}tmp $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/ install -p -m 644 examples/{b,w}tmp $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/
install -p -m 755 examples/logrotate.cron $RPM_BUILD_ROOT%{_sysconfdir}/cron.daily/logrotate install -p -m 644 examples/logrotate.{service,timer} $RPM_BUILD_ROOT%{_unitdir}/
# Make sure logrotate is able to run on read-only root # Make sure logrotate is able to run on read-only root
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rwtab.d mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rwtab.d
@ -91,15 +93,27 @@ if [ ! -d %{_localstatedir}/lib/logrotate/ -a -f %{_localstatedir}/lib/logrotate
cp -a %{_localstatedir}/lib/logrotate.status %{_localstatedir}/lib/logrotate cp -a %{_localstatedir}/lib/logrotate.status %{_localstatedir}/lib/logrotate
fi fi
%post
%systemd_post logrotate.{service,timer}
# If there is any cron daemon configured, enable the systemd timer to avoid
# breaking the configuration silently when upgrading from 3.14.0-4 or
# earlier versions
%triggerin -- logrotate < 3.14.0-5
[ -e %{_sysconfdir}/crontab -o -e %{_sysconfdir}/anacrontab -o -e %{_sysconfdir}/fcrontab ] \
&& %{_bindir}/systemctl enable --now logrotate.timer &>/dev/null || :
%preun
%systemd_preun logrotate.{service,timer}
%files %files
%{!?_licensedir:%global license %%doc} %{!?_licensedir:%global license %%doc}
%license COPYING %license COPYING
%doc ChangeLog.md %doc ChangeLog.md
%{_sbindir}/logrotate %{_sbindir}/logrotate
%{_unitdir}/logrotate.{service,timer}
%{_mandir}/man8/logrotate.8* %{_mandir}/man8/logrotate.8*
%{_mandir}/man5/logrotate.conf.5* %{_mandir}/man5/logrotate.conf.5*
%dir %{_sysconfdir}/cron.daily
%config(noreplace) %{_sysconfdir}/cron.daily/logrotate
%config(noreplace) %{_sysconfdir}/logrotate.conf %config(noreplace) %{_sysconfdir}/logrotate.conf
%dir %{_sysconfdir}/logrotate.d %dir %{_sysconfdir}/logrotate.d
%config(noreplace) %{_sysconfdir}/logrotate.d/{b,w}tmp %config(noreplace) %{_sysconfdir}/logrotate.d/{b,w}tmp
@ -110,6 +124,7 @@ fi
%changelog %changelog
* Wed Nov 21 2018 Alejandro Domínguez Muñoz <adomu@net-c.com> - 3.14.0-5 * Wed Nov 21 2018 Alejandro Domínguez Muñoz <adomu@net-c.com> - 3.14.0-5
- add make as a build dependency - add make as a build dependency
- replace cron job with a systemd timer unit (#1502085, #1655153)
* Fri Aug 10 2018 Kamil Dudka <kdudka@redhat.com> - 3.14.0-4 * Fri Aug 10 2018 Kamil Dudka <kdudka@redhat.com> - 3.14.0-4
- fix programming mistakes detected by Coverity Analysis - fix programming mistakes detected by Coverity Analysis