2020-08-29 19:10:59 +00:00
|
|
|
from json import dumps
|
|
|
|
|
|
|
|
from bundlewrap.metadata import MetadataJSONEncoder
|
|
|
|
|
2022-02-12 10:24:50 +00:00
|
|
|
if node.os == 'debian':
|
|
|
|
actions = {
|
|
|
|
# For some reason, this module doesn't get auto-loaded on debian,
|
|
|
|
# even if installation of zfsutils-linux tries to start
|
|
|
|
# zfs-mount.service. We have no choice but to do it manually.
|
|
|
|
'modprobe_zfs': {
|
|
|
|
'command': 'modprobe zfs',
|
|
|
|
'unless': 'lsmod | grep ^zfs',
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:zfs-dkms',
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_apt:zfs-zed',
|
|
|
|
'pkg_apt:zfsutils-linux',
|
|
|
|
'zfs_dataset:',
|
|
|
|
'zfs_pool:',
|
|
|
|
},
|
|
|
|
'comment': 'If this fails, do a dist-upgrade, reinstall zfs-dkms, reboot',
|
2020-10-31 09:11:15 +00:00
|
|
|
},
|
2022-02-12 10:24:50 +00:00
|
|
|
}
|
2020-08-29 19:10:59 +00:00
|
|
|
|
|
|
|
files = {
|
2020-10-25 15:39:35 +00:00
|
|
|
'/etc/modprobe.d/zfs.conf': {
|
2020-08-29 19:10:59 +00:00
|
|
|
'source': 'zfs-modprobe.conf',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2022-03-12 07:54:33 +00:00
|
|
|
'/etc/systemd/system/zfs-import-scan.service.d/bundlewrap.conf': {
|
|
|
|
'source': 'zfs-import-scan-override.service',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
|
|
|
},
|
|
|
|
},
|
2022-12-18 10:43:38 +00:00
|
|
|
'/etc/systemd/system/zfs-zed.service.d/bundlewrap.conf': {
|
|
|
|
'source': 'zfs-zed-override.service',
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
|
|
|
'svc_systemd:zfs-zed:restart'
|
|
|
|
},
|
|
|
|
},
|
2020-08-29 19:10:59 +00:00
|
|
|
'/etc/zfs-snapshot-config.json': {
|
|
|
|
'content': dumps(
|
2021-02-18 17:12:25 +00:00
|
|
|
node.metadata.get('zfs/snapshots', {}),
|
2020-08-29 19:10:59 +00:00
|
|
|
cls=MetadataJSONEncoder, # turns sets into sorted lists
|
|
|
|
indent=4,
|
|
|
|
sort_keys=True,
|
|
|
|
) + '\n',
|
|
|
|
},
|
|
|
|
'/etc/zfs/zed.d/zed.rc': {
|
|
|
|
'content': 'ZED_EMAIL_ADDR="hostmaster@kunbox.net"\nZED_EMAIL_PROG="mail"\nZED_NOTIFY_INTERVAL_SECS=3600\n',
|
|
|
|
'mode': '0600',
|
2020-10-25 15:39:35 +00:00
|
|
|
'triggers': {
|
2020-11-12 17:40:39 +00:00
|
|
|
'svc_systemd:zfs-zed:restart'
|
2020-10-25 15:39:35 +00:00
|
|
|
},
|
2020-08-29 19:10:59 +00:00
|
|
|
},
|
2021-06-25 18:04:30 +00:00
|
|
|
'/usr/local/sbin/telegraf-per-dataset': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-08-29 19:10:59 +00:00
|
|
|
'/usr/local/sbin/zfs-auto-snapshot': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-11-10 09:35:01 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_zfs_auto_snapshot': {
|
2020-08-29 19:10:59 +00:00
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-11-10 09:35:01 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_zfs_old_snapshots': {
|
2020-08-29 19:10:59 +00:00
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-11-10 09:35:01 +00:00
|
|
|
"/usr/local/share/icinga/plugins/check_zfs_volumes": {
|
2020-08-29 19:10:59 +00:00
|
|
|
'mode': '0755',
|
|
|
|
'content_type': 'mako',
|
|
|
|
},
|
2020-11-10 09:35:01 +00:00
|
|
|
"/usr/local/share/icinga/plugins/check_zpool_online": {
|
2020-08-29 19:10:59 +00:00
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-11-10 09:35:01 +00:00
|
|
|
"/usr/local/share/icinga/plugins/check_zpool_space": {
|
2020-08-29 19:10:59 +00:00
|
|
|
'mode': '0755',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
2022-03-12 07:54:33 +00:00
|
|
|
'zfs-import-scan.service': {
|
|
|
|
'needs': {
|
|
|
|
'file:/etc/systemd/system/zfs-import-scan.service.d/bundlewrap.conf',
|
|
|
|
},
|
|
|
|
'before': {
|
|
|
|
'svc_systemd:zfs-import-cache.service',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'zfs-import-cache.service': {
|
|
|
|
'running': None,
|
|
|
|
'enabled': False,
|
|
|
|
'masked': True,
|
|
|
|
},
|
|
|
|
'zfs-mount.service': {},
|
2022-02-12 10:24:50 +00:00
|
|
|
'zfs-zed': {},
|
2022-03-12 07:54:33 +00:00
|
|
|
'zfs.target': {
|
|
|
|
'running': None,
|
|
|
|
},
|
|
|
|
'zfs-import.target': {
|
|
|
|
'running': None,
|
|
|
|
},
|
2020-08-29 19:10:59 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 15:52:26 +00:00
|
|
|
for name, attrs in node.metadata.get('zfs/datasets', {}).items():
|
|
|
|
zfs_datasets[name] = attrs
|
|
|
|
|
|
|
|
if 'mountpoint' not in attrs:
|
|
|
|
zfs_datasets[name]['canmount'] = 'off'
|
2022-02-12 17:09:40 +00:00
|
|
|
zfs_datasets[name]['mountpoint'] = 'none'
|
2022-02-12 17:56:54 +00:00
|
|
|
elif 'canmount' not in attrs:
|
2021-12-28 15:52:26 +00:00
|
|
|
zfs_datasets[name]['canmount'] = 'on'
|
2020-08-29 19:10:59 +00:00
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for name, attrs in node.metadata.get('zfs/pools', {}).items():
|
2021-08-17 16:09:51 +00:00
|
|
|
zfs_pools[name] = attrs
|
2020-08-29 19:10:59 +00:00
|
|
|
|
2022-03-12 07:54:33 +00:00
|
|
|
if (not node.os == 'debian' or node.os_version[0] > 10) and 'autotrim' not in attrs:
|
|
|
|
zfs_pools[name]['autotrim'] = True
|
2020-08-29 19:10:59 +00:00
|
|
|
|
|
|
|
directories = {
|
|
|
|
"/etc/zfs-snapshot-backup-pre.d": {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
"/etc/zfs-snapshot-backup-post.d": {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
}
|
2021-05-15 18:32:23 +00:00
|
|
|
|
|
|
|
if node.metadata.get('zfs/filesystems_with_backup_snapshots', {}) and node.has_bundle('backup-client'):
|
|
|
|
files['/etc/backup-pre-hooks.d/99-zfs-snapshots'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'source': 'backup-pre-hook',
|
|
|
|
'mode': '0755',
|
|
|
|
}
|