Add zfs-scrub
This commit is contained in:
parent
579d4b6a47
commit
015a8fa5d4
5 changed files with 89 additions and 1 deletions
11
files/zfs-scrub.service
Normal file
11
files/zfs-scrub.service
Normal file
|
@ -0,0 +1,11 @@
|
|||
[Unit]
|
||||
Description=zpool scrub
|
||||
|
||||
[Service]
|
||||
Nice=19
|
||||
IOSchedulingClass=idle
|
||||
KillSignal=SIGINT
|
||||
ExecStart=/usr/local/bin/zfs-scrub.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
10
files/zfs-scrub.timer
Normal file
10
files/zfs-scrub.timer
Normal file
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=Monthly zpool scrub
|
||||
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
RandomizedDelaySec=86400
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -11,3 +11,7 @@ borg_passphrase = b_borg_passphrase.decode('utf-8')
|
|||
|
||||
b_borg_healthchecks = get_secret(b'1$2$AbHQ2WFelnJfIi5SjEtgAugd3xHSJDfikh0RBV3QY80=$Z0FBQUFBQmdGOWdKZnp1d3B0YUJUck9kOVNBVWxTRjJZZnpubUZmNmV0cmlCUm9kLUhYNndqWkhMOG5WQU44ZUVMQ2lEdW1jLUhSOTJub0VMZWFWdHBBb0JKdVptanNCQ2xyQXQ2cEdfMjBaUy00Y2dlcnJzc1ViaE5sQ0RUUS1idkViQ0hOOWdRWUlqZElQSlAzYmpjSUl5bjNuTDhDLTNBPT0=')
|
||||
borg_healthchecks = b_borg_healthchecks.decode('utf-8')
|
||||
|
||||
b_zfs_healthchecks = get_secret(b'1$2$dsh3T6POjU9RvOqr_Itg1paAckP4K2cIRN8L22OsGVo=$Z0FBQUFBQmdIa21UYUtGeVdmLWNvbGhYUDNfNzdTd0gwN21ISHRTV3B6SDBrTFA4aTRCaF84bWY5UlhYV3RSOUxsekRyTVd4REhqczZTTW00WHhzSjJSV2JuNjZ5NXdGWmtrQjFkWjNNdmZYTm4xMXUxOHlYNlpJb0pGQmoyb0JTajRjanQwMHlEUzhUSTNjRFlXenBwdDRTMzA5c2NzeFJBPT0=')
|
||||
zfs_healthchecks = b_zfs_healthchecks.decode('utf-8')
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from pyinfra import host
|
||||
from pyinfra.operations import server, files, systemd
|
||||
from pyinfra.operations import server, files, systemd, apt
|
||||
|
||||
SUDO = True
|
||||
|
||||
|
@ -19,6 +19,12 @@ SUDO = True
|
|||
# sdc 8:32 0 223.6G 0 disk
|
||||
# └─sdc1 8:33 0 24G 0 part
|
||||
|
||||
apt.packages(
|
||||
name='Install packages',
|
||||
packages=['zfsutils-linux'],
|
||||
update=True,
|
||||
)
|
||||
|
||||
if not host.fact.command('lsblk | grep sda4 || true'):
|
||||
server.shell(
|
||||
name='Create sda4 for zpool',
|
||||
|
@ -92,3 +98,42 @@ if not host.fact.command('lxc storage volume list default | grep images || true'
|
|||
commands=['lxc storage volume create default images', 'lxc config set storage.images_volume default/images']
|
||||
)
|
||||
|
||||
files.template(
|
||||
name='Push zfs-scrub script',
|
||||
src='templates/zfs-scrub.sh.j2',
|
||||
dest='/usr/local/bin/zfs-scrub.sh',
|
||||
mode='700',
|
||||
user='root',
|
||||
group='root',
|
||||
)
|
||||
|
||||
files.put(
|
||||
name='Push zfs-scrub timer',
|
||||
src='files/zfs-scrub.timer',
|
||||
dest='/etc/systemd/system/zfs-scrub.timer',
|
||||
user='root',
|
||||
group='root',
|
||||
mode='644',
|
||||
)
|
||||
|
||||
files.put(
|
||||
name='Push zfs-scrub service',
|
||||
src='files/zfs-scrub.service',
|
||||
dest='/etc/systemd/system/zfs-scrub.service',
|
||||
user='root',
|
||||
group='root',
|
||||
mode='644',
|
||||
)
|
||||
|
||||
systemd.daemon_reload(
|
||||
name='Reload systemd',
|
||||
user_mode=False,
|
||||
)
|
||||
|
||||
systemd.service(
|
||||
name='Enable zfs-scrub timer',
|
||||
service='zfs-scrub.timer',
|
||||
running=True,
|
||||
enabled=True,
|
||||
)
|
||||
|
||||
|
|
18
templates/zfs-scrub.sh.j2
Normal file
18
templates/zfs-scrub.sh.j2
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
# https://serverfault.com/questions/538978/how-to-run-a-command-once-a-zfs-scrub-completes
|
||||
set -euo pipefail
|
||||
|
||||
curl -m 10 --retry 5 {{ host.data.zfs_healthchecks }}/start
|
||||
zpool scrub local
|
||||
# wait until scrub is finished
|
||||
while zpool status local | grep -q 'scan: *scrub in progress'; do
|
||||
zpool status local
|
||||
sleep 600
|
||||
done
|
||||
|
||||
zpool status local
|
||||
|
||||
# Get stdout from journalctl
|
||||
LOG=$(journalctl -o cat -r -u zfs-scrub.service -n 100)
|
||||
curl -fsS -m 10 --retry 5 --data-raw "$LOG" {{ host.data.zfs_healthchecks }}
|
||||
exit 0
|
Reference in a new issue