diff --git a/mlocate.cron b/mlocate-run-updatedb similarity index 66% rename from mlocate.cron rename to mlocate-run-updatedb index 2fed430..7d3f2ac 100644 --- a/mlocate.cron +++ b/mlocate-run-updatedb @@ -1,5 +1,4 @@ #!/bin/sh + nodevs=$(< /proc/filesystems awk '$1 == "nodev" && $2 != "rootfs" && $2 != "zfs" { print $2 }') -renice +19 -p $$ >/dev/null 2>&1 -ionice -c2 -n7 -p $$ >/dev/null 2>&1 /usr/bin/updatedb -f "$nodevs" diff --git a/mlocate-updatedb.service b/mlocate-updatedb.service new file mode 100644 index 0000000..fcd7032 --- /dev/null +++ b/mlocate-updatedb.service @@ -0,0 +1,14 @@ +[Unit] +Description=Update a database for mlocate + +[Service] +Type=oneshot +ExecStart=/usr/libexec/mlocate-run-updatedb +Nice=19 +IOSchedulingClass=2 +IOSchedulingPriority=7 + +PrivateTmp=true +PrivateDevices=true +PrivateNetwork=true +ProtectSystem=true diff --git a/mlocate-updatedb.timer b/mlocate-updatedb.timer new file mode 100644 index 0000000..9472537 --- /dev/null +++ b/mlocate-updatedb.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Updates mlocate database every day + +[Timer] +OnCalendar=daily +AccuracySec=24h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/mlocate.spec b/mlocate.spec index 604a404..2f7b05a 100644 --- a/mlocate.spec +++ b/mlocate.spec @@ -3,16 +3,18 @@ Summary: An utility for finding files by name Name: mlocate Version: 0.26 -Release: 10%{?dist} +Release: 11%{?dist} License: GPLv2 URL: https://fedorahosted.org/mlocate/ Group: Applications/System Source0: https://fedorahosted.org/releases/m/l/mlocate/mlocate-%{version}.tar.xz Source1: updatedb.conf -Source2: mlocate.cron -Requires: crontabs +Source2: mlocate-run-updatedb +Source3: mlocate-updatedb.service +Source4: mlocate-updatedb.timer Requires(pre): shadow-utils Requires(post): grep, sed +BuildRequires: systemd Provides: bundled(gnulib) Obsoletes: slocate <= 2.7-30 @@ -36,7 +38,10 @@ make install DESTDIR=$RPM_BUILD_ROOT INSTALL='install -p' groupname=slocate mkdir -p $RPM_BUILD_ROOT{%{_sysconfdir},/etc/cron.daily} install -p -m 644 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/updatedb.conf -install -p -m 750 %{SOURCE2} $RPM_BUILD_ROOT/etc/cron.daily/mlocate +install -D -p -m 750 %{SOURCE2} $RPM_BUILD_ROOT%{_libexecdir}/mlocate-run-updatedb +install -D -p -m 644 %{SOURCE3} $RPM_BUILD_ROOT%{_unitdir}/mlocate-updatedb.service +install -D -p -m 644 %{SOURCE4} $RPM_BUILD_ROOT%{_unitdir}/mlocate-updatedb.timer + # %%ghost semantics is so stupid touch $RPM_BUILD_ROOT%{_localstatedir}/lib/mlocate/mlocate.db @@ -50,18 +55,33 @@ exit 0 if /bin/grep -q '^[^#]*DAILY_UPDATE' %{_sysconfdir}/updatedb.conf; then /bin/sed -i.rpmsave -e '/DAILY_UPDATE/s/^/#/' %{_sysconfdir}/updatedb.conf fi +%systemd_post mlocate-updatedb.timer + +%preun +%systemd_preun mlocate-updatedb.timer + +%postun +%systemd_postun_with_restart mlocate-updatedb.timer + +%triggerin -- %{name} < 0.26-11 +/usr/bin/systemctl start mlocate-updatedb.timer %files -f mlocate.lang %doc AUTHORS COPYING NEWS README -%attr(0700,-,-) %config(noreplace) /etc/cron.daily/mlocate %config(noreplace) %{_sysconfdir}/updatedb.conf %attr(2711,root,slocate) %{_bindir}/locate +%{_unitdir}/mlocate-updatedb.service +%{_unitdir}/mlocate-updatedb.timer +%{_libexecdir}/mlocate-run-updatedb %{_bindir}/updatedb %{_mandir}/man*/* %dir %attr(0750,root,slocate) %{_localstatedir}/lib/mlocate %ghost %attr(0640,root,slocate) %{_localstatedir}/lib/mlocate/mlocate.db %changelog +* Tue Jun 9 2015 Michal Sekletar - 0.26-11 +- migrate from cron job to systemd timer + * Tue May 26 2015 Michal Sekletar - 0.26-10 - prune path /var/lib/ceph (#1223582)