Add zfs scrubbing and filesystem trim
This commit is contained in:
parent
6f87c559e0
commit
e1beb5e38c
86
machine.yml
86
machine.yml
@ -114,3 +114,89 @@
|
||||
daemon_reload: true
|
||||
when:
|
||||
systemd_status_mail_service_file is changed
|
||||
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# ZFS scrubbing.
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
|
||||
- name: Zpool status mail script
|
||||
template:
|
||||
src: ./root/usr/local/bin/zpool-status-mail.j2
|
||||
dest: /usr/local/bin/zpool-status-mail
|
||||
mode: 0755
|
||||
|
||||
- name: Zfs scrub service file
|
||||
copy:
|
||||
src: ./root/etc/systemd/system/zfs-scrub@.service
|
||||
dest: /etc/systemd/system/zfs-scrub@.service
|
||||
mode: 0644
|
||||
register: systemd_zfs_scrub_service_file
|
||||
|
||||
- name: Zfs scrub timer file
|
||||
copy:
|
||||
src: ./root/etc/systemd/system/zfs-scrub-monthly@.timer
|
||||
dest: /etc/systemd/system/zfs-scrub-monthly@.timer
|
||||
mode: 0644
|
||||
register: systemd_zfs_scrub_monthly_timer_file
|
||||
|
||||
- name: SystemD daemon reload
|
||||
systemd:
|
||||
daemon_reload: true
|
||||
when:
|
||||
systemd_zfs_scrub_service_file is changed or
|
||||
systemd_zfs_scrub_monthly_timer_file is changed
|
||||
|
||||
- name: Enable zfs scrub of bpool
|
||||
service:
|
||||
name: zfs-scrub-monthly@bpool.timer
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Enable zfs scrub of rpool
|
||||
service:
|
||||
name: zfs-scrub-monthly@rpool.timer
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# Filesystem TRIM.
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
|
||||
- name: Enable fstrim
|
||||
service:
|
||||
name: fstrim.timer
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Zfs trim service file
|
||||
copy:
|
||||
src: ./root/etc/systemd/system/zfs-trim@.service
|
||||
dest: /etc/systemd/system/zfs-trim@.service
|
||||
mode: 0644
|
||||
register: systemd_zfs_trim_service_file
|
||||
|
||||
- name: Zfs trim timer file
|
||||
copy:
|
||||
src: ./root/etc/systemd/system/zfs-trim-monthly@.timer
|
||||
dest: /etc/systemd/system/zfs-trim-monthly@.timer
|
||||
mode: 0644
|
||||
register: systemd_zfs_trim_monthly_timer_file
|
||||
|
||||
- name: SystemD daemon reload
|
||||
systemd:
|
||||
daemon_reload: true
|
||||
when:
|
||||
systemd_zfs_trim_service_file is changed or
|
||||
systemd_zfs_trim_monthly_timer_file is changed
|
||||
|
||||
- name: Enable zfs trim of bpool
|
||||
service:
|
||||
name: zfs-trim-monthly@bpool.timer
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Enable zfs trim of rpool
|
||||
service:
|
||||
name: zfs-trim-monthly@rpool.timer
|
||||
enabled: yes
|
||||
state: started
|
||||
|
8
root/etc/systemd/system/status-mail@.service
Normal file
8
root/etc/systemd/system/status-mail@.service
Normal file
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Status email for %i
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/systemd-mail %i
|
||||
User=nobody
|
||||
Group=systemd-journal
|
12
root/etc/systemd/system/zfs-scrub-monthly@.timer
Normal file
12
root/etc/systemd/system/zfs-scrub-monthly@.timer
Normal file
@ -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
|
17
root/etc/systemd/system/zfs-scrub@.service
Normal file
17
root/etc/systemd/system/zfs-scrub@.service
Normal file
@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Zpool scrub on %i
|
||||
Documentation=man:zpool-scrub(8)
|
||||
Requires=zfs.target
|
||||
After=zfs.target
|
||||
ConditionACPower=true
|
||||
ConditionPathIsDirectory=/sys/module/zfs
|
||||
OnFailure=status-mail@%n.service
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=-/etc/default/zfs
|
||||
ExecStart=/bin/sh -c '\
|
||||
if /usr/sbin/zpool status %i | grep -q "scrub in progress"; then\
|
||||
exec /usr/sbin/zpool wait -t scrub %i;\
|
||||
else exec /usr/sbin/zpool scrub -w %i; fi'
|
||||
ExecStop=-/bin/sh -c '/usr/sbin/zpool scrub -p %i 2>/dev/null || true'
|
||||
ExecStopPost=/bin/sh -c '/usr/local/bin/zpool-status-mail %i'
|
12
root/etc/systemd/system/zfs-trim-monthly@.timer
Normal file
12
root/etc/systemd/system/zfs-trim-monthly@.timer
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Monthly zpool trim timer for %i
|
||||
Documentation=man:zpool-trim(8)
|
||||
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
Persistent=true
|
||||
RandomizedDelaySec=1h
|
||||
Unit=zfs-trim@%i.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
16
root/etc/systemd/system/zfs-trim@.service
Normal file
16
root/etc/systemd/system/zfs-trim@.service
Normal file
@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=Zpool trim on %i
|
||||
Documentation=man:zpool-trim(8)
|
||||
Requires=zfs.target
|
||||
After=zfs.target
|
||||
ConditionACPower=true
|
||||
ConditionPathIsDirectory=/sys/module/zfs
|
||||
OnFailure=status-mail@%n.service
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=-/etc/default/zfs
|
||||
ExecStart=/bin/sh -c '\
|
||||
if /usr/sbin/zpool status %i | grep -q "(trimming)"; then\
|
||||
exec /usr/sbin/zpool wait -t trim %i;\
|
||||
else exec /usr/sbin/zpool trim -w %i; fi'
|
||||
ExecStop=-/bin/sh -c '/usr/sbin/zpool trim -s %i 2>/dev/null || true'
|
11
root/usr/local/bin/zpool-status-mail.j2
Normal file
11
root/usr/local/bin/zpool-status-mail.j2
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
/usr/sbin/sendmail -t <<SYSTEMDMAIL
|
||||
To: root
|
||||
From: systemd <{{ hostname }}>
|
||||
Subject: zpool status $1
|
||||
Content-Transfer-Encoding: 8bit
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
$(zpool status "$1")
|
||||
SYSTEMDMAIL
|
Loading…
Reference in New Issue
Block a user