]> git.proxmox.com Git - mirror_zfs.git/commitdiff
systemd: add weekly and monthly scrub timers
authorGeorgy Yakovlev <168902+gyakovlev@users.noreply.github.com>
Thu, 16 Dec 2021 19:47:22 +0000 (11:47 -0800)
committerGitHub <noreply@github.com>
Thu, 16 Dec 2021 19:47:22 +0000 (11:47 -0800)
Timers can be enabled as follows:

systemctl enable zfs-scrub-weekly@rpool.timer --now
systemctl enable zfs-scrub-monthly@datapool.timer --now

Each timer will pull in zfs-scrub@${poolname}.service, which is not
schedule-specific.

Added PERIODIC SCRUB section to zpool-scrub.8.

Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
Closes #12193

etc/systemd/system/.gitignore
etc/systemd/system/Makefile.am
etc/systemd/system/zfs-scrub-monthly@.timer.in [new file with mode: 0644]
etc/systemd/system/zfs-scrub-weekly@.timer.in [new file with mode: 0644]
etc/systemd/system/zfs-scrub@.service.in [new file with mode: 0644]
man/man8/zpool-scrub.8

index efada54ad9321dad709b7ba63ae127aec8d015a3..4813c65a25a8ca2c91d730a67630c3a1e10f7056 100644 (file)
@@ -1,3 +1,4 @@
 *.service
 *.target
 *.preset
+*.timer
index c374a52ac7db1ede3a34015bad366a9d6d6998e0..5e65e1db420c1412fba1a5e853a98c165f6b18ac 100644 (file)
@@ -12,7 +12,10 @@ systemdunit_DATA = \
        zfs-volume-wait.service \
        zfs-import.target \
        zfs-volumes.target \
-       zfs.target
+       zfs.target \
+       zfs-scrub-monthly@.timer \
+       zfs-scrub-weekly@.timer \
+       zfs-scrub@.service
 
 SUBSTFILES += $(systemdpreset_DATA) $(systemdunit_DATA)
 
diff --git a/etc/systemd/system/zfs-scrub-monthly@.timer.in b/etc/systemd/system/zfs-scrub-monthly@.timer.in
new file mode 100644 (file)
index 0000000..9030684
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Monthly zpool scrub timer for %i
+Documentation=man:zpool-scrub(8)
+
+[Timer]
+OnCalendar=monthly
+Persistent=true
+RandomizedDelaySec=1h
+Unit=zfs-scrub@%i.service
+
+[Install]
+WantedBy=timers.target
diff --git a/etc/systemd/system/zfs-scrub-weekly@.timer.in b/etc/systemd/system/zfs-scrub-weekly@.timer.in
new file mode 100644 (file)
index 0000000..ede6995
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Weekly zpool scrub timer for %i
+Documentation=man:zpool-scrub(8)
+
+[Timer]
+OnCalendar=weekly
+Persistent=true
+RandomizedDelaySec=1h
+Unit=zfs-scrub@%i.service
+
+[Install]
+WantedBy=timers.target
diff --git a/etc/systemd/system/zfs-scrub@.service.in b/etc/systemd/system/zfs-scrub@.service.in
new file mode 100644 (file)
index 0000000..bebe91d
--- /dev/null
@@ -0,0 +1,14 @@
+[Unit]
+Description=zpool scrub on %i
+Documentation=man:zpool-scrub(8)
+Requires=zfs.target
+After=zfs.target
+ConditionACPower=true
+ConditionPathIsDirectory=/sys/module/zfs
+
+[Service]
+ExecStart=/bin/sh -c '\
+if @sbindir@/zpool status %i | grep "scrub in progress"; then\
+exec @sbindir@/zpool wait -t scrub %i;\
+else exec @sbindir@/zpool scrub -w %i; fi'
+ExecStop=-/bin/sh -c '@sbindir@/zpool scrub -p %i 2>/dev/null || true'
index 768f7153929041a482c878f9c820cc566c6c93c6..69ae825b6158a09db2ed858095761863aca70e5f 100644 (file)
@@ -116,8 +116,29 @@ scanned at 100M/s, and 68.4M of that file data has been
 scrubbed sequentially at 10.0M/s.
 .El
 .El
+.Sh PERIODIC SCRUB
+On machines using systemd, scrub timers can be enabled on per-pool basis.
+.Nm weekly
+and
+.Nm monthly
+timer units are provided.
+.Bl -tag -width Ds
+.It Xo
+.Xc
+.Nm systemctl
+.Cm enable
+.Cm zfs-scrub-\fIweekly\fB@\fIrpool\fB.timer
+.Cm --now
+.It Xo
+.Xc
+.Nm systemctl
+.Cm enable
+.Cm zfs-scrub-\fImonthly\fB@\fIotherpool\fB.timer
+.Cm --now
+.El
 .
 .Sh SEE ALSO
+.Xr systemd.timer 5 ,
 .Xr zpool-iostat 8 ,
 .Xr zpool-resilver 8 ,
 .Xr zpool-status 8