-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathautoscrub.sls
40 lines (35 loc) · 1.16 KB
/
autoscrub.sls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
zpool-scrub@.timer:
file.managed:
- name: /etc/systemd/system/zpool-scrub@.timer
- contents: |
[Unit]
Description=ZFS Pool Scrub Timer on %i
[Timer]
OnCalendar=monthly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target
- require:
- file: zpool-scrub@.service
zpool-scrub@.service:
file.managed:
- name: /etc/systemd/system/zpool-scrub@.service
- contents: |
[Unit]
Description=ZFS Pool Scrub Service on %i, executes once per month for 4 months, then once every 6 months
Requires=zfs.target
After=zfs.target
ConditionACPower=true
ConditionPathIsDirectory=/sys/module/zfs
[Service]
ExecStart=/usr/bin/bash -c \
'count=$(cat /etc/zfs/zpool-scrub-%I.counter 2>/dev/null || echo 0); \
if [[ $count -lt 4 || ($count -ge 4 && $((count % 6)) == 0) ]]; then zpool scrub -w %I; fi; \
echo $((count + 1)) > /etc/zfs/zpool-scrub-%I.counter'
zpool-scrub:
cmd.run:
- name: systemctl daemon-reload
- onchanges:
- file: zpool-scrub@.service
- file: zpool-scrub@.timer