From 3602c89b10b3f7182e5f774f1a0370da5239788f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 May 2021 14:42:47 +0200 Subject: [PATCH] Start the service and timer in %posttrans The initial run takes about 30s on my laptop, which is not too bad. On machines with large and/or slow storage, it might take significantly longer, but it's in the background anyway, so this should be acceptable. It's nice to be able to use the service soon after installation. --- plocate.spec | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plocate.spec b/plocate.spec index 027f062..0677a4e 100644 --- a/plocate.spec +++ b/plocate.spec @@ -33,18 +33,38 @@ mlocate in nearly all aspects, and is fast on SSDs and non-SSDs alike. install -p -D -m 0644 %{SOURCE1} %{buildroot}%{_sysusersdir}/plocate.conf +# A state file to carry information from %%post to %%posttrans. See +# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_saving_state_between_scriptlets. +%global plocate_start_now %{_localstatedir}/lib/rpm-state/plocate_start_now + %pre %sysusers_create_compat %{SOURCE1} %post %systemd_post plocate-updatedb.service plocate-updatedb.timer +if [ $1 == 1 ] && [ -d /run/systemd ]; then + touch %{plocate_start_now} || : +fi + %preun %systemd_preun plocate-updatedb.service plocate-updatedb.timer %postun %systemd_postun_with_restart plocate-updatedb.service plocate-updatedb.timer +%posttrans +# The timer runs once per day. On new installs, let's start both the +# timer and the service immediately in the background, so that the db +# becomes populated. When people install this package onto a running +# system, it's reasonable to assume that they want to use the database. +if [ -f %{plocate_start_now} ]; then + rm %{plocate_start_now} || : + if systemctl is-enabled plocate-updatedb.timer &>/dev/null; then + systemctl start --no-block plocate-updatedb.timer plocate-updatedb.service || : + fi +fi + %files %license COPYING %doc README @@ -65,6 +85,7 @@ install -p -D -m 0644 %{SOURCE1} %{buildroot}%{_sysusersdir}/plocate.conf %changelog * Wed May 12 2021 Zbigniew Jędrzejewski-Szmek - 1.1.7-1 - Resolve comments from initial review +- Start the service and timer in %%posttrans * Fri Feb 19 2021 Zbigniew Jędrzejewski-Szmek - 1.1.4-1 - First version