Merge pull request #23396 from mayflower/feature/zfs-auto-scrub
zfs.autoScrub service: init
This commit is contained in:
commit
4487a993b2
@ -13,12 +13,14 @@ let
|
|||||||
cfgZfs = config.boot.zfs;
|
cfgZfs = config.boot.zfs;
|
||||||
cfgSnapshots = config.services.zfs.autoSnapshot;
|
cfgSnapshots = config.services.zfs.autoSnapshot;
|
||||||
cfgSnapFlags = cfgSnapshots.flags;
|
cfgSnapFlags = cfgSnapshots.flags;
|
||||||
|
cfgScrub = config.services.zfs.autoScrub;
|
||||||
|
|
||||||
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
||||||
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
||||||
|
|
||||||
enableAutoSnapshots = cfgSnapshots.enable;
|
enableAutoSnapshots = cfgSnapshots.enable;
|
||||||
enableZfs = inInitrd || inSystem || enableAutoSnapshots;
|
enableAutoScrub = cfgScrub.enable;
|
||||||
|
enableZfs = inInitrd || inSystem || enableAutoSnapshots || enableAutoScrub;
|
||||||
|
|
||||||
kernel = config.boot.kernelPackages;
|
kernel = config.boot.kernelPackages;
|
||||||
|
|
||||||
@ -217,6 +219,37 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.zfs.autoScrub = {
|
||||||
|
enable = mkOption {
|
||||||
|
default = false;
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Enables periodic scrubbing of ZFS pools.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
interval = mkOption {
|
||||||
|
default = "Sun, 02:00";
|
||||||
|
type = types.str;
|
||||||
|
example = "daily";
|
||||||
|
description = ''
|
||||||
|
Systemd calendar expression when to scrub ZFS pools. See
|
||||||
|
<citerefentry><refentrytitle>systemd.time</refentrytitle>
|
||||||
|
<manvolnum>5</manvolnum></citerefentry>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
pools = mkOption {
|
||||||
|
default = [];
|
||||||
|
type = types.listOf types.str;
|
||||||
|
example = [ "tank" ];
|
||||||
|
description = ''
|
||||||
|
List of ZFS pools to periodically scrub. If empty, all pools
|
||||||
|
will be scrubbed.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
@ -282,7 +315,7 @@ in
|
|||||||
zfsSupport = true;
|
zfsSupport = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.etc."zfs/zed.d".source = "${packages.zfsUser}/etc/zfs/zed.d/*";
|
environment.etc."zfs/zed.d".source = "${packages.zfsUser}/etc/zfs/zed.d/";
|
||||||
|
|
||||||
system.fsPackages = [ packages.zfsUser ]; # XXX: needed? zfs doesn't have (need) a fsck
|
system.fsPackages = [ packages.zfsUser ]; # XXX: needed? zfs doesn't have (need) a fsck
|
||||||
environment.systemPackages = [ packages.zfsUser ]
|
environment.systemPackages = [ packages.zfsUser ]
|
||||||
@ -391,5 +424,31 @@ in
|
|||||||
};
|
};
|
||||||
}) snapshotNames);
|
}) snapshotNames);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(mkIf enableAutoScrub {
|
||||||
|
systemd.services.zfs-scrub = {
|
||||||
|
description = "ZFS pools scrubbing";
|
||||||
|
after = [ "zfs-import.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
};
|
||||||
|
script = ''
|
||||||
|
${packages.zfsUser}/bin/zpool scrub ${
|
||||||
|
if cfgScrub.pools != [] then
|
||||||
|
(concatStringsSep " " cfgScrub.pools)
|
||||||
|
else
|
||||||
|
"$(${packages.zfsUser}/bin/zpool list -H -o name)"
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.timers.zfs-scrub = {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = cfgScrub.interval;
|
||||||
|
Persistent = "yes";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user