Skip to content

Commit

Permalink
Run "makecache" periodically to keep the cache ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonmessmer committed Oct 22, 2024
1 parent b2c8300 commit 0cc67cc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(dnf5 LANGUAGES CXX C VERSION ${VERSION_PRIME}.${VERSION_MAJOR}.${VERSION
cmake_policy(VERSION ${CMAKE_VERSION})

set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set (SYSTEMD_DIR "/usr/lib/systemd/system")

message("Building ${PROJECT_NAME} version ${PROJECT_VERSION}")

Expand Down Expand Up @@ -134,6 +135,7 @@ include_directories("${PROJECT_SOURCE_DIR}/common")

# libdnf5
add_subdirectory("common")
add_subdirectory("etc")
add_subdirectory("include")
add_subdirectory("libdnf5")
add_subdirectory("libdnf5-cli")
Expand Down
11 changes: 11 additions & 0 deletions dnf5.spec
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,23 @@ DNF5 is a command-line package manager that automates the process of installing,
upgrading, configuring, and removing computer programs in a consistent manner.
It supports RPM packages, modulemd modules, and comps groups & environments.

%post
%systemd_post dnf5-makecache.timer

%preun
%systemd_preun dnf5-makecache.timer

%postun
%systemd_postun_with_restart dnf5-makecache.timer

%files -f dnf5.lang
%{_bindir}/dnf5
%if %{with dnf5_obsoletes_dnf}
%{_bindir}/dnf
%{_bindir}/yum
%endif
%{_unitdir}/dnf5-makecache.service
%{_unitdir}/dnf5-makecache.timer

%if 0%{?fedora} || 0%{?rhel} > 10
%{_bindir}/microdnf
Expand Down
1 change: 1 addition & 0 deletions etc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory("systemd")
5 changes: 5 additions & 0 deletions etc/systemd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(systemd_FILES
dnf5-makecache.service
dnf5-makecache.timer)

install(FILES ${systemd_FILES} DESTINATION ${SYSTEMD_DIR})
15 changes: 15 additions & 0 deletions etc/systemd/dnf5-makecache.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=dnf5 makecache
# On systems managed by either rpm-ostree/ostree, dnf is read-only;
# while someone might theoretically want the cache updated, in practice
# anyone who wants that could override this via a file in /etc.
ConditionPathExists=!/run/ostree-booted

After=network-online.target

[Service]
Type=oneshot
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/usr/bin/dnf5 makecache
15 changes: 15 additions & 0 deletions etc/systemd/dnf5-makecache.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=dnf5 makecache
ConditionKernelCommandLine=!rd.live.image
# See comment in dnf5-makecache.service
ConditionPathExists=!/run/ostree-booted
Wants=network-online.target

[Timer]
OnBootSec=10min
OnUnitInactiveSec=1h
RandomizedDelaySec=60m
Unit=dnf5-makecache.service

[Install]
WantedBy=timers.target

0 comments on commit 0cc67cc

Please sign in to comment.