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.
This commit is contained in:
parent
65eada882b
commit
3602c89b10
21
plocate.spec
21
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 <zbyszek@in.waw.pl> - 1.1.7-1
|
||||
- Resolve comments from initial review
|
||||
- Start the service and timer in %%posttrans
|
||||
|
||||
* Fri Feb 19 2021 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 1.1.4-1
|
||||
- First version
|
||||
|
|
Loading…
Reference in New Issue