From dfd880466ea17d2e312e144292575c72ea8c9b2b5bd3b871f6fdbad7571d8839 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 15 Jan 2018 15:09:04 +0000 Subject: [PATCH 1/2] Accepting request 559643 from home:1Antoine1:branches:filesystems - Fix systemd timers enabled even if period is set to none: * Micro change in pull-request-36.patch. - Clean spec file: * Removed support for suse_version <= 1210. * Removed call to btrfsmaintenance-refresh-cron.sh upon deletion (not needed anymore since we use systemd timers which are handled by macros). * Ran spec-cleaner. OBS-URL: https://build.opensuse.org/request/show/559643 OBS-URL: https://build.opensuse.org/package/show/filesystems/btrfsmaintenance?expand=0&rev=30 --- btrfsmaintenance.changes | 12 +++++++ btrfsmaintenance.spec | 72 +++++++++++----------------------------- pull-request-36.patch | 2 +- 3 files changed, 33 insertions(+), 53 deletions(-) diff --git a/btrfsmaintenance.changes b/btrfsmaintenance.changes index 18ade6b..4e44ee0 100644 --- a/btrfsmaintenance.changes +++ b/btrfsmaintenance.changes @@ -1,3 +1,15 @@ +------------------------------------------------------------------- +Fri Dec 22 18:42:10 UTC 2017 - antoine.belvire@opensuse.org + +- Fix systemd timers enabled even if period is set to none: + * Micro change in pull-request-36.patch. +- Clean spec file: + * Removed support for suse_version <= 1210. + * Removed call to btrfsmaintenance-refresh-cron.sh upon deletion + (not needed anymore since we use systemd timers which are + handled by macros). + * Ran spec-cleaner. + ------------------------------------------------------------------- Sun Dec 17 12:18:45 CET 2017 - kukuk@suse.de diff --git a/btrfsmaintenance.spec b/btrfsmaintenance.spec index 651a6fa..82614c6 100644 --- a/btrfsmaintenance.spec +++ b/btrfsmaintenance.spec @@ -20,7 +20,6 @@ %if ! %{defined _fillupdir} %define _fillupdir /var/adm/fillup-templates %endif - Name: btrfsmaintenance Version: 0.3.1 Release: 0 @@ -31,19 +30,17 @@ Url: https://github.com/kdave/btrfsmaintenance Source0: %{name}-%{version}.tar.bz2 # PATCH-FIX-OPENSUSE btrfsmaintenance-0.3.1-fix-rpm-db-path.patch -- Fix RPM database path for Tumbleweed Patch0: btrfsmaintenance-0.3.1-fix-rpm-db-path.patch +# PATCH-FIX-UPSTREAM pull-request-36.patch -- Add systemd timer Patch1: pull-request-36.patch +# PATCH-FIX-UPSTREAM btrfsmaintenance-switch-to-timer.patch -- Refresh systemd timers, not cron tasks Patch2: btrfsmaintenance-switch-to-timer.patch +BuildRequires: systemd +Requires: btrfsprogs Requires: zypp-plugin-python Requires: libzypp(plugin:commit) -#Recommends: cron Supplements: btrfsprogs -Requires: btrfsprogs -BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch %{?systemd_requires} -%if 0%{?suse_version} >= 1210 -BuildRequires: systemd -%endif %description Scripts for btrfs maintenance tasks like periodic scrub, balance, trim or defrag @@ -51,20 +48,16 @@ on selected mountpoints or directories. %prep %setup -q -%if 0%{?suse_version} > 1320 +%if 0%{?suse_version} > 1320 %patch0 %endif %patch1 -p1 -%patch2 -p0 +%patch2 %build %install -# fix build error on openSUSE and SLE -mkdir -p %{buildroot}%{_sysconfdir}/cron.daily/ -mkdir -p %{buildroot}%{_sysconfdir}/cron.weekly/ -mkdir -p %{buildroot}%{_sysconfdir}/cron.monthly/ - +# scripts install -m 755 -d %{buildroot}%{_datadir}/%{name} install -m 755 btrfs-defrag.sh %{buildroot}%{_datadir}/%{name} install -m 755 btrfs-balance.sh %{buildroot}%{_datadir}/%{name} @@ -73,7 +66,7 @@ install -m 755 btrfs-trim.sh %{buildroot}%{_datadir}/%{name} install -m 755 btrfsmaintenance-refresh-cron.sh %{buildroot}%{_datadir}/%{name} install -m 644 btrfsmaintenance-functions %{buildroot}%{_datadir}/%{name} -%if 0%{?suse_version} >= 1210 +# systemd services and timers install -m 755 -d %{buildroot}%{_unitdir} install -m 644 -D btrfsmaintenance-refresh.service %{buildroot}%{_unitdir} install -m 644 -D btrfs-balance.service %{buildroot}%{_unitdir} @@ -86,62 +79,40 @@ install -m 644 -D btrfs-scrub.timer %{buildroot}%{_unitdir} install -m 644 -D btrfs-trim.timer %{buildroot}%{_unitdir} install -m 755 -d %{buildroot}%{_sbindir} ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcbtrfsmaintenance-refresh -%else -# just a hack, but sufficient -install -m 755 -d %{buildroot}%{_sysconfdir}/cron.hourly -ln -s %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh %{buildroot}%{_sysconfdir}/cron.hourly/ -%endif -install -m 755 -d %{buildroot}/usr/lib/zypp/plugins/commit -install -m 755 -D btrfs-defrag-plugin.py %{buildroot}/usr/lib/zypp/plugins/commit +# zypp plugin +install -m 755 -d %{buildroot}%{_libexecdir}/zypp/plugins/commit +install -m 755 -D btrfs-defrag-plugin.py %{buildroot}%{_libexecdir}/zypp/plugins/commit +# config install -m 755 -d %{buildroot}%{_fillupdir} install -m 644 -D sysconfig.btrfsmaintenance %{buildroot}%{_fillupdir} -%post -%service_add_post btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer -%{fillup_only btrfsmaintenance} - -%if 0%{?suse_version} >= 1210 - %pre # if the new service files don't exist, we migrate from # old version with old script, remove cron symlinks [ ! -f %{_unitdir}/btrfs-balance.timer -a -f %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh ] && %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh uninstall %service_add_pre btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer +%post +%service_add_post btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer +%{fillup_only btrfsmaintenance} + %preun %service_del_preun btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer -if [ $1 -eq 0 ]; then - # Remove cron files in %%preun only if it's a package removal. - # If it's an upgrade, the %%post section of the new package has - # already refreshed the cron links, so we shall not remove them. - %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh systemd-timer uninstall -fi %postun %service_del_postun btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer -%endif - -%if 0%{?suse_version} < 1210 - -%preun -if [ $1 -eq 0 ]; then - %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh uninstall -fi -%endif %files -%defattr(-,root,root) %doc COPYING README.md %{_fillupdir}/sysconfig.btrfsmaintenance %dir %{_datadir}/%{name} %{_datadir}/%{name}/* -%dir /usr/lib/zypp/ -%dir /usr/lib/zypp/plugins -%dir /usr/lib/zypp/plugins/commit -/usr/lib/zypp/plugins/commit/btrfs-defrag-plugin.py -%if 0%{?suse_version} >= 1210 +%dir %{_libexecdir}/zypp/ +%dir %{_libexecdir}/zypp/plugins +%dir %{_libexecdir}/zypp/plugins/commit +%{_libexecdir}/zypp/plugins/commit/btrfs-defrag-plugin.py %{_unitdir}/btrfsmaintenance-refresh.service %{_unitdir}/btrfs-balance.service %{_unitdir}/btrfs-defrag.service @@ -152,8 +123,5 @@ fi %{_unitdir}/btrfs-scrub.timer %{_unitdir}/btrfs-trim.timer %{_sbindir}/rcbtrfsmaintenance-refresh -%else -%{_sysconfdir}/cron.hourly/btrfsmaintenance-refresh-cron.sh -%endif %changelog diff --git a/pull-request-36.patch b/pull-request-36.patch index f3e2575..d8f8d7e 100644 --- a/pull-request-36.patch +++ b/pull-request-36.patch @@ -277,7 +277,7 @@ index da68283..7e92170 100755 case "$PERIOD" in - daily|weekly|monthly) -+ uninstall) ++ uninstall|none) + systemctl stop "$SERVICE".timer &> /dev/null + systemctl disable "$SERVICE".timer &> /dev/null + rm -rf /etc/systemd/system/"$SERVICE".timer.d From d8536ea64fc601f694ca867cd8d2af77536d87a84917dba8e12070b2205cd442 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 19 Jan 2018 19:10:54 +0000 Subject: [PATCH 2/2] Accepting request 567778 from home:dsterba:branches:filesystems - update to version 0.4 OBS-URL: https://build.opensuse.org/request/show/567778 OBS-URL: https://build.opensuse.org/package/show/filesystems/btrfsmaintenance?expand=0&rev=31 --- btrfsmaintenance-0.3.1-fix-rpm-db-path.patch | 18 -- btrfsmaintenance-0.3.1.tar.bz2 | 3 - btrfsmaintenance-0.4.tar.bz2 | 3 + btrfsmaintenance-switch-to-timer.patch | 24 -- btrfsmaintenance.changes | 18 +- btrfsmaintenance.spec | 16 +- pull-request-36.patch | 300 ------------------- 7 files changed, 23 insertions(+), 359 deletions(-) delete mode 100644 btrfsmaintenance-0.3.1-fix-rpm-db-path.patch delete mode 100644 btrfsmaintenance-0.3.1.tar.bz2 create mode 100644 btrfsmaintenance-0.4.tar.bz2 delete mode 100644 btrfsmaintenance-switch-to-timer.patch delete mode 100644 pull-request-36.patch diff --git a/btrfsmaintenance-0.3.1-fix-rpm-db-path.patch b/btrfsmaintenance-0.3.1-fix-rpm-db-path.patch deleted file mode 100644 index 8d969a7..0000000 --- a/btrfsmaintenance-0.3.1-fix-rpm-db-path.patch +++ /dev/null @@ -1,18 +0,0 @@ -RPM database location has changed from /var/lib/rpm to /usr/lib/sysimage/rpm -for openSUSE Tumbleweed. - -See https://lists.opensuse.org/opensuse-factory/2017-11/msg00188.html. ---- -diff -up ./btrfs-defrag-plugin.py.orig ./btrfs-defrag-plugin.py ---- ./btrfs-defrag-plugin.py.orig 2017-11-07 22:56:51.559813001 +0100 -+++ ./btrfs-defrag-plugin.py 2017-11-07 22:57:38.027814927 +0100 -@@ -24,7 +24,7 @@ import subprocess - DEBUG=False - EXTENT_SIZE=64*1024*1024 - LOGFILE='/tmp/btrfs-defrag-plugin.log' --PATH='/var/lib/rpm' -+PATH='/usr/lib/sysimage/rpm/' - - def dbg(args): - if not DEBUG: return - diff --git a/btrfsmaintenance-0.3.1.tar.bz2 b/btrfsmaintenance-0.3.1.tar.bz2 deleted file mode 100644 index 5c2e841..0000000 --- a/btrfsmaintenance-0.3.1.tar.bz2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:65304ed51c7402ece2989f155a5da4be8380b85c4418dcd48a0c631f89c9ca1d -size 16240 diff --git a/btrfsmaintenance-0.4.tar.bz2 b/btrfsmaintenance-0.4.tar.bz2 new file mode 100644 index 0000000..aa31a39 --- /dev/null +++ b/btrfsmaintenance-0.4.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46fb835cf45ed27f9fb957d49c4569bbff0a346a60f437f46bf130f1bd394092 +size 17511 diff --git a/btrfsmaintenance-switch-to-timer.patch b/btrfsmaintenance-switch-to-timer.patch deleted file mode 100644 index 7baa0bf..0000000 --- a/btrfsmaintenance-switch-to-timer.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- btrfsmaintenance-refresh-cron.sh -+++ btrfsmaintenance-refresh-cron.sh 2017/12/17 11:12:22 -@@ -91,6 +91,10 @@ - - case "$BTRFS_TIMER_IMPLEMENTATION" in - systemd-timer) -+ # Deinstall cron jobs, don't run it twice. -+ for SCRIPT in btrfs-scrub btrfs-defrag btrfs-balance btrfs-trim; do -+ refresh_cron uninstall ${SCRIPT}.sh -+ done - refresh_timer "$BTRFS_SCRUB_PERIOD" btrfs-scrub - refresh_timer "$BTRFS_DEFRAG_PERIOD" btrfs-defrag - refresh_timer "$BTRFS_BALANCE_PERIOD" btrfs-balance ---- btrfsmaintenance-refresh.service -+++ btrfsmaintenance-refresh.service 2017/12/17 11:04:07 -@@ -3,7 +3,7 @@ - After=local-fs.target - - [Service] --ExecStart=/usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh -+ExecStart=/usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh systemd-timer - Type=oneshot - - [Install] diff --git a/btrfsmaintenance.changes b/btrfsmaintenance.changes index 4e44ee0..07f57a8 100644 --- a/btrfsmaintenance.changes +++ b/btrfsmaintenance.changes @@ -1,8 +1,24 @@ +------------------------------------------------------------------- +Mon Jan 15 00:00:00 CET 2018 - dsterba@suse.cz + +- update to version 0.4 + - add support for systemd timers and use them by default; the alternative + cron scripts are still present (#29, #36) + - add automatic monitoring (via systemd.path) of the config file, + no manual updates by btrfsmaintenance-refresh.service needed (#38) + - fix RPM database path detection + - spec file cleanups + - documentation updates +- removed patches: + - btrfsmaintenance-0.3.1-fix-rpm-db-path.patch (upstream) + - btrfsmaintenance-switch-to-timer.patch (upstream) + - pull-request-36.patch (upstream) + ------------------------------------------------------------------- Fri Dec 22 18:42:10 UTC 2017 - antoine.belvire@opensuse.org - Fix systemd timers enabled even if period is set to none: - * Micro change in pull-request-36.patch. + * Micro change in pull-request-36.patch (bsc#1075884) - Clean spec file: * Removed support for suse_version <= 1210. * Removed call to btrfsmaintenance-refresh-cron.sh upon deletion diff --git a/btrfsmaintenance.spec b/btrfsmaintenance.spec index 82614c6..9b2a389 100644 --- a/btrfsmaintenance.spec +++ b/btrfsmaintenance.spec @@ -1,7 +1,7 @@ # # spec file for package btrfsmaintenance # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -20,20 +20,15 @@ %if ! %{defined _fillupdir} %define _fillupdir /var/adm/fillup-templates %endif + Name: btrfsmaintenance -Version: 0.3.1 +Version: 0.4 Release: 0 Summary: Scripts for btrfs periodic maintenance tasks License: GPL-2.0 Group: System/Base Url: https://github.com/kdave/btrfsmaintenance Source0: %{name}-%{version}.tar.bz2 -# PATCH-FIX-OPENSUSE btrfsmaintenance-0.3.1-fix-rpm-db-path.patch -- Fix RPM database path for Tumbleweed -Patch0: btrfsmaintenance-0.3.1-fix-rpm-db-path.patch -# PATCH-FIX-UPSTREAM pull-request-36.patch -- Add systemd timer -Patch1: pull-request-36.patch -# PATCH-FIX-UPSTREAM btrfsmaintenance-switch-to-timer.patch -- Refresh systemd timers, not cron tasks -Patch2: btrfsmaintenance-switch-to-timer.patch BuildRequires: systemd Requires: btrfsprogs Requires: zypp-plugin-python @@ -48,11 +43,6 @@ on selected mountpoints or directories. %prep %setup -q -%if 0%{?suse_version} > 1320 -%patch0 -%endif -%patch1 -p1 -%patch2 %build diff --git a/pull-request-36.patch b/pull-request-36.patch deleted file mode 100644 index d8f8d7e..0000000 --- a/pull-request-36.patch +++ /dev/null @@ -1,300 +0,0 @@ -From a192d335442d2fe74b3b6f7feb83a07325441361 Mon Sep 17 00:00:00 2001 -From: Luigi 'Comio' Mantellini -Date: Wed, 2 Aug 2017 17:27:21 +0200 -Subject: [PATCH 1/2] Add support for systemd timers. - ---- - btrfs-balance.service | 10 +++++ - btrfs-balance.timer | 11 ++++++ - btrfs-defrag.service | 10 +++++ - btrfs-defrag.timer | 11 ++++++ - btrfs-scrub.service | 10 +++++ - btrfs-scrub.timer | 11 ++++++ - btrfs-trim.service | 10 +++++ - btrfs-trim.timer | 11 ++++++ - btrfsmaintenance-refresh-cron.sh | 80 ++++++++++++++++++++++++++++++++-------- - btrfsmaintenance.spec | 16 ++++++++ - prepare-release.sh | 1 + - 11 files changed, 165 insertions(+), 16 deletions(-) - create mode 100644 btrfs-balance.service - create mode 100644 btrfs-balance.timer - create mode 100644 btrfs-defrag.service - create mode 100644 btrfs-defrag.timer - create mode 100644 btrfs-scrub.service - create mode 100644 btrfs-scrub.timer - create mode 100644 btrfs-trim.service - create mode 100644 btrfs-trim.timer - -diff --git a/btrfs-balance.service b/btrfs-balance.service -new file mode 100644 -index 0000000..146f997 ---- /dev/null -+++ b/btrfs-balance.service -@@ -0,0 +1,10 @@ -+[Unit] -+Description=Balance block groups on a btrfs filesystem -+Documentation=man:btrfs-balance -+After=fstrim.service btrfs-trim.service btrfs-scrub.service -+ -+[Service] -+Type=oneshot -+ExecStart=/usr/share/btrfsmaintenance/btrfs-balance.sh -+IOSchedulingClass=idle -+CPUSchedulingPolicy=idle -diff --git a/btrfs-balance.timer b/btrfs-balance.timer -new file mode 100644 -index 0000000..72f9f1f ---- /dev/null -+++ b/btrfs-balance.timer -@@ -0,0 +1,11 @@ -+[Unit] -+Description=Balance block groups on a btrfs filesystem -+Documentation=man:btrfs-balance -+ -+[Timer] -+OnCalendar=monthly -+AccuracySec=1h -+Persistent=true -+ -+[Install] -+WantedBy=timers.target -diff --git a/btrfs-defrag.service b/btrfs-defrag.service -new file mode 100644 -index 0000000..12d3c92 ---- /dev/null -+++ b/btrfs-defrag.service -@@ -0,0 +1,10 @@ -+[Unit] -+Description=Defragment file data on a mounted filesystem -+Documentation=man:btrfs-filesystem -+After=fstrim.service btrfs-trim.service btrfs-scrub.service -+ -+[Service] -+Type=oneshot -+ExecStart=/usr/share/btrfsmaintenance/btrfs-defrag.sh -+IOSchedulingClass=idle -+CPUSchedulingPolicy=idle -diff --git a/btrfs-defrag.timer b/btrfs-defrag.timer -new file mode 100644 -index 0000000..dd5b867 ---- /dev/null -+++ b/btrfs-defrag.timer -@@ -0,0 +1,11 @@ -+[Unit] -+Description=Defragment file data and/or directory metadata -+Documentation=man:btrfs-filesystem -+ -+[Timer] -+OnCalendar=monthly -+AccuracySec=1h -+Persistent=true -+ -+[Install] -+WantedBy=timers.target -diff --git a/btrfs-scrub.service b/btrfs-scrub.service -new file mode 100644 -index 0000000..40012f3 ---- /dev/null -+++ b/btrfs-scrub.service -@@ -0,0 +1,10 @@ -+[Unit] -+Description=Scrub btrfs filesystem, verify block checksums -+Documentation=man:fstrim -+After=fstrim.service btrfs-trim.service -+ -+[Service] -+Type=oneshot -+ExecStart=/usr/share/btrfsmaintenance/btrfs-scrub.sh -+IOSchedulingClass=idle -+CPUSchedulingPolicy=idle -diff --git a/btrfs-scrub.timer b/btrfs-scrub.timer -new file mode 100644 -index 0000000..2ceabdf ---- /dev/null -+++ b/btrfs-scrub.timer -@@ -0,0 +1,11 @@ -+[Unit] -+Description=Scrub btrfs filesystem, verify block checksums -+Documentation=man:btrfs-scrub -+ -+[Timer] -+OnCalendar=monthly -+AccuracySec=1h -+Persistent=true -+ -+[Install] -+WantedBy=timers.target -diff --git a/btrfs-trim.service b/btrfs-trim.service -new file mode 100644 -index 0000000..d09da40 ---- /dev/null -+++ b/btrfs-trim.service -@@ -0,0 +1,10 @@ -+[Unit] -+Description=Discard unused blocks on a mounted filesystem -+Documentation=man:fstrim -+Conflicts=fstrim.service -+ -+[Service] -+Type=oneshot -+ExecStart=/usr/share/btrfsmaintenance/btrfs-trim.sh -+IOSchedulingClass=idle -+CPUSchedulingPolicy=idle -diff --git a/btrfs-trim.timer b/btrfs-trim.timer -new file mode 100644 -index 0000000..03e824f ---- /dev/null -+++ b/btrfs-trim.timer -@@ -0,0 +1,11 @@ -+[Unit] -+Description=Discard unused blocks on a mounted filesystem -+Documentation=man:fstrim -+ -+[Timer] -+OnCalendar=monthly -+AccuracySec=1h -+Persistent=true -+ -+[Install] -+WantedBy=timers.target -diff --git a/btrfsmaintenance-refresh-cron.sh b/btrfsmaintenance-refresh-cron.sh -index ed1053e..da68283 100755 ---- a/btrfsmaintenance-refresh-cron.sh -+++ b/btrfsmaintenance-refresh-cron.sh -@@ -16,17 +16,6 @@ export PATH - - SCRIPTS=/usr/share/btrfsmaintenance - --if [ "$1" = 'uninstall' ]; then -- for SCRIPT in btrfs-scrub.sh btrfs-defrag.sh btrfs-balance.sh btrfs-trim.sh; do -- for PERIOD in daily weekly monthly; do -- LINK="${SCRIPT%.*}" -- FILE="/etc/cron.$PERIOD/$LINK" -- rm -f "$FILE" -- done -- done -- exit 0 --fi -- - if [ -f /etc/sysconfig/btrfsmaintenance ]; then - . /etc/sysconfig/btrfsmaintenance - fi -@@ -35,7 +24,18 @@ if [ -f /etc/default/btrfsmaintenance ]; then - . /etc/default/btrfsmaintenance - fi - --refresh_period() { -+case "$1" in -+ cron) -+ BTRFS_TIMER_IMPLEMENTATION="cron" -+ shift -+ ;; -+ systemd-timer|timer) -+ BTRFS_TIMER_IMPLEMENTATION="systemd-timer" -+ shift -+ ;; -+esac -+ -+refresh_cron() { - EXPECTED="$1" - SCRIPT="$2" - echo "Refresh script $SCRIPT for $EXPECTED" -@@ -52,7 +52,55 @@ refresh_period() { - done - } - --refresh_period "$BTRFS_SCRUB_PERIOD" btrfs-scrub.sh --refresh_period "$BTRFS_DEFRAG_PERIOD" btrfs-defrag.sh --refresh_period "$BTRFS_BALANCE_PERIOD" btrfs-balance.sh --refresh_period "$BTRFS_TRIM_PERIOD" btrfs-trim.sh -+refresh_timer() { -+ PERIOD="$1" -+ SERVICE="$2" -+ echo "Refresh timer $SERVICE for $PERIOD" -+ -+ case "$PERIOD" in -+ daily|weekly|monthly) -+ mkdir -p /etc/systemd/system/"$SERVICE".timer.d/ -+ cat << EOF > /etc/systemd/system/"$SERVICE".timer.d/schedule.conf -+[Timer] -+OnCalendar=$PERIOD -+EOF -+ systemctl enable "$SERVICE".timer &> /dev/null -+ systemctl start "$SERVICE".timer &> /dev/null -+ ;; -+ *) -+ systemctl stop "$SERVICE".timer &> /dev/null -+ systemctl disable "$SERVICE".timer &> /dev/null -+ rm -rf /etc/systemd/system/"$SERVICE".timer.d -+ ;; -+ esac -+} -+ -+if [ "$1" = 'uninstall' ]; then -+ for SCRIPT in btrfs-scrub btrfs-defrag btrfs-balance btrfs-trim; do -+ case "$BTRFS_TIMER_IMPLEMENTATION" in -+ systemd-timer) -+ refresh_timer uninstall ${SCRIPT} -+ ;; -+ *) -+ refresh_cron uninstall ${SCRIPT}.sh -+ ;; -+ esac -+ done -+ exit 0 -+fi -+ -+case "$BTRFS_TIMER_IMPLEMENTATION" in -+ systemd-timer) -+ refresh_timer "$BTRFS_SCRUB_PERIOD" btrfs-scrub -+ refresh_timer "$BTRFS_DEFRAG_PERIOD" btrfs-defrag -+ refresh_timer "$BTRFS_BALANCE_PERIOD" btrfs-balance -+ refresh_timer "$BTRFS_TRIM_PERIOD" btrfs-trim -+ ;; -+ *) -+ refresh_cron "$BTRFS_SCRUB_PERIOD" btrfs-scrub.sh -+ refresh_cron "$BTRFS_DEFRAG_PERIOD" btrfs-defrag.sh -+ refresh_cron "$BTRFS_BALANCE_PERIOD" btrfs-balance.sh -+ refresh_cron "$BTRFS_TRIM_PERIOD" btrfs-trim.sh -+ ;; -+esac -+ -From e5e26ffaa50d7cfdef8291d4ff72e95061438fcc Mon Sep 17 00:00:00 2001 -From: Luigi 'Comio' Mantellini -Date: Wed, 6 Dec 2017 14:31:06 +0100 -Subject: [PATCH 2/2] Don't limit OnCalendar to daily, weekly and monthly. - ---- - btrfsmaintenance-refresh-cron.sh | 12 ++++++------ - 1 file changed, 6 insertions(+), 6 deletions(-) - -diff --git a/btrfsmaintenance-refresh-cron.sh b/btrfsmaintenance-refresh-cron.sh -index da68283..7e92170 100755 ---- a/btrfsmaintenance-refresh-cron.sh -+++ b/btrfsmaintenance-refresh-cron.sh -@@ -58,7 +58,12 @@ refresh_timer() { - echo "Refresh timer $SERVICE for $PERIOD" - - case "$PERIOD" in -- daily|weekly|monthly) -+ uninstall|none) -+ systemctl stop "$SERVICE".timer &> /dev/null -+ systemctl disable "$SERVICE".timer &> /dev/null -+ rm -rf /etc/systemd/system/"$SERVICE".timer.d -+ ;; -+ *) - mkdir -p /etc/systemd/system/"$SERVICE".timer.d/ - cat << EOF > /etc/systemd/system/"$SERVICE".timer.d/schedule.conf - [Timer] -@@ -67,11 +72,6 @@ EOF - systemctl enable "$SERVICE".timer &> /dev/null - systemctl start "$SERVICE".timer &> /dev/null - ;; -- *) -- systemctl stop "$SERVICE".timer &> /dev/null -- systemctl disable "$SERVICE".timer &> /dev/null -- rm -rf /etc/systemd/system/"$SERVICE".timer.d -- ;; - esac - } -