Skip to content

Commit

Permalink
systemd: add weekly and monthly scrub timers
Browse files Browse the repository at this point in the history
Timers can be enabled as follows:

systemctl enable [email protected] --now
systemctl enable [email protected] --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 <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Georgy Yakovlev <[email protected]>
Closes openzfs#12193
  • Loading branch information
gyakovlev authored and nicman23 committed Aug 22, 2022
1 parent da06726 commit 9011f70
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions etc/systemd/system/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.service
*.target
*.preset
*.timer
5 changes: 4 additions & 1 deletion etc/systemd/system/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ systemdunit_DATA = \
zfs-volume-wait.service \
zfs-import.target \
zfs-volumes.target \
zfs.target
zfs.target \
[email protected] \
[email protected] \
[email protected]

SUBSTFILES += $(systemdpreset_DATA) $(systemdunit_DATA)

Expand Down
12 changes: 12 additions & 0 deletions etc/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions etc/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions etc/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -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'
21 changes: 21 additions & 0 deletions man/man8/zpool-scrub.8
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9011f70

Please sign in to comment.