[neon/neon/settings/Neon/release-lts] /: add a unit to ensure the apt cache gets auto cleaned daily
Harald Sitter
null at kde.org
Mon May 3 12:06:38 BST 2021
Git commit 75e0a8133e515b0d27e694a53664124304d5fb8d by Harald Sitter.
Committed on 03/05/2021 at 11:02.
Pushed by sitter into branch 'Neon/release-lts'.
add a unit to ensure the apt cache gets auto cleaned daily
there's really no reason not to do it. chances are something does it on
ubuntu that we either disabled/removed/donthave. it's unreasonable to
keep forever growing caches on a desktop system
M +1 -0 debian/neon-settings-2.install
M +10 -1 debian/rules
A +21 -0 lib/systemd/system/neon-apt-clean.service
A +13 -0 lib/systemd/system/neon-apt-clean.timer
https://invent.kde.org/neon/neon/settings/commit/75e0a8133e515b0d27e694a53664124304d5fb8d
diff --git a/debian/neon-settings-2.install b/debian/neon-settings-2.install
index 7c0337f..5534f43 100644
--- a/debian/neon-settings-2.install
+++ b/debian/neon-settings-2.install
@@ -1,2 +1,3 @@
etc/
usr/
+lib/
diff --git a/debian/rules b/debian/rules
index 626da9f..d3f901b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,7 +1,7 @@
#!/usr/bin/make -f
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2016 Jonathan Riddell <jr at jriddell.org>
-# SPDX-FileCopyrightText: 2018-2020 Harald Sitter <sitter at kde.org>
+# SPDX-FileCopyrightText: 2018-2021 Harald Sitter <sitter at kde.org>
export DH_VERBOSE=1
@@ -12,6 +12,15 @@ override_dh_usrlocal:
true
override_dh_installsystemd:
+ # Random safe guard. dh_installsystemd doesn't handle /usr/lib/systemd same as /lib/systemd 🙄
+ if find debian/neon-settings-*/lib/systemd/ -type f -not \( -name '*.service' -or -name '*.timer' -or -name '*.slice' \) | grep '.'; then \
+ echo " !!! Only put unit files in /lib/systemd, everything else in /usr/lib/systemd!"; \
+ exit 1; \
+ fi
+
+ # Perferrably use lib/systemd/system/ instead of placing units in debian/
+ # Also mind https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=987989
+ dh_installsystemd
dh_installsystemd --no-start --name=neon-update-calamares-groups
dh_installsystemd --no-start --name=neon-flathub
dh_installsystemd --no-start --name=neon-packagekit-offline-update-policy
diff --git a/lib/systemd/system/neon-apt-clean.service b/lib/systemd/system/neon-apt-clean.service
new file mode 100644
index 0000000..9de3415
--- /dev/null
+++ b/lib/systemd/system/neon-apt-clean.service
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
+# SPDX-FileCopyrightText: 2021 Harald Sitter <sitter at kde.org>
+
+[Unit]
+Description=Apt cache cleanup
+ConditionACPower=true
+# No point starting (and failing) when the lock is currently held.
+ConditionPathExists=!/var/cache/apt/archives/lock
+# If packagekit is running wait until it is done. Otherwise we might block it with a temporary apt lock.
+After=packagekit.service
+
+[Service]
+ExecStart=/usr/bin/apt-get autoclean
+Nice=9
+IOSchedulingPriority=6
+# With our niceness we need to ensure the process doesn't get starved and never terminates.
+# Also, be quick about it. Clean holds the lock - the quicker it is, the better!
+# If it doesn't finish within this time frame because of IO contention or general drive speed we'll simply continue
+# cleaning the next day and so and so forth until eventually everything is clean again and the daily cleanup is
+# completing in a more reasonable time frame from thereon out.
+RuntimeMaxSec=5 minutes
diff --git a/lib/systemd/system/neon-apt-clean.timer b/lib/systemd/system/neon-apt-clean.timer
new file mode 100644
index 0000000..6ea70b1
--- /dev/null
+++ b/lib/systemd/system/neon-apt-clean.timer
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
+# SPDX-FileCopyrightText: 2021 Harald Sitter <sitter at kde.org>
+
+[Unit]
+Description=Apt cache cleanup timer
+
+[Timer]
+Persistent=true
+OnCalendar=daily
+RandomizedDelaySec=16 hours
+
+[Install]
+WantedBy=timers.target
More information about the Neon-commits
mailing list