diff --git a/btrfsmaintenance.changes b/btrfsmaintenance.changes index 709a1fc..a69ab59 100644 --- a/btrfsmaintenance.changes +++ b/btrfsmaintenance.changes @@ -1,3 +1,19 @@ +------------------------------------------------------------------- +Wed Dec 6 15:55:53 CET 2017 - kukuk@suse.de + +- pull-request-36.patch: update patch + +------------------------------------------------------------------- +Wed Dec 6 13:39:46 CET 2017 - kukuk@suse.de + +- Don't call btrfsmaintenance-refresh-cron.sh in %post, this is + done already by the systemd macros + +------------------------------------------------------------------- +Tue Dec 5 18:53:08 UTC 2017 - kukuk@suse.com + +- Add patch to use systemd timer instead of cron (pull-request-36.patch) + ------------------------------------------------------------------- Thu Nov 23 13:44:40 UTC 2017 - rbrown@suse.com diff --git a/btrfsmaintenance.spec b/btrfsmaintenance.spec index 5c0cf68..aec8d37 100644 --- a/btrfsmaintenance.spec +++ b/btrfsmaintenance.spec @@ -23,7 +23,7 @@ Name: btrfsmaintenance Version: 0.3.1 -Release: 0 +Release: 10.2 Summary: Scripts for btrfs periodic maintenance tasks License: GPL-2.0 Group: System/Base @@ -31,9 +31,10 @@ 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 +Patch1: pull-request-36.patch Requires: zypp-plugin-python Requires: libzypp(plugin:commit) -Recommends: cron +#Recommends: cron Supplements: btrfsprogs Requires: btrfsprogs BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -52,6 +53,7 @@ on selected mountpoints or directories. %if 0%{?suse_version} > 1320 %patch0 %endif +%patch1 -p1 %build @@ -72,6 +74,14 @@ install -m 644 btrfsmaintenance-functions %{buildroot}%{_datadir}/%{name} %if 0%{?suse_version} >= 1210 install -m 755 -d %{buildroot}%{_unitdir} install -m 644 -D btrfsmaintenance-refresh.service %{buildroot}%{_unitdir} +install -m 644 -D btrfs-balance.service %{buildroot}%{_unitdir} +install -m 644 -D btrfs-defrag.service %{buildroot}%{_unitdir} +install -m 644 -D btrfs-scrub.service %{buildroot}%{_unitdir} +install -m 644 -D btrfs-trim.service %{buildroot}%{_unitdir} +install -m 644 -D btrfs-balance.timer %{buildroot}%{_unitdir} +install -m 644 -D btrfs-defrag.timer %{buildroot}%{_unitdir} +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 @@ -87,28 +97,28 @@ 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 -%service_add_post btrfsmaintenance-refresh.service -%endif -%{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh %if 0%{?suse_version} >= 1210 %pre -%service_add_pre btrfsmaintenance-refresh.service +# 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 %preun -%service_del_preun btrfsmaintenance-refresh.service +%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 uninstall + %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh systemd-timer uninstall fi %postun -%service_del_postun btrfsmaintenance-refresh.service +%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 @@ -130,8 +140,15 @@ fi %dir /usr/lib/zypp/plugins/commit /usr/lib/zypp/plugins/commit/btrfs-defrag-plugin.py %if 0%{?suse_version} >= 1210 -%dir %{_unitdir} %{_unitdir}/btrfsmaintenance-refresh.service +%{_unitdir}/btrfs-balance.service +%{_unitdir}/btrfs-defrag.service +%{_unitdir}/btrfs-scrub.service +%{_unitdir}/btrfs-trim.service +%{_unitdir}/btrfs-balance.timer +%{_unitdir}/btrfs-defrag.timer +%{_unitdir}/btrfs-scrub.timer +%{_unitdir}/btrfs-trim.timer %{_sbindir}/rcbtrfsmaintenance-refresh %else %{_sysconfdir}/cron.hourly/btrfsmaintenance-refresh-cron.sh diff --git a/pull-request-36.patch b/pull-request-36.patch new file mode 100644 index 0000000..f3e2575 --- /dev/null +++ b/pull-request-36.patch @@ -0,0 +1,300 @@ +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) ++ 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 + } +