bundlewrap/bundles/zfs/items.py

102 lines
2.7 KiB
Python
Raw Normal View History

from json import dumps
2021-02-12 19:37:36 +00:00
#from os.path import join
from bundlewrap.metadata import MetadataJSONEncoder
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',
},
}
files = {
2020-10-25 15:39:35 +00:00
'/etc/modprobe.d/zfs.conf': {
'source': 'zfs-modprobe.conf',
'content_type': 'mako',
'mode': '0755',
},
'/etc/zfs-snapshot-config.json': {
'content': dumps(
node.metadata.get('zfs/snapshots', {}),
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
},
},
2021-06-25 18:04:30 +00:00
'/usr/local/sbin/telegraf-per-dataset': {
'mode': '0755',
},
'/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': {
'mode': '0755',
},
2020-11-10 09:35:01 +00:00
'/usr/local/share/icinga/plugins/check_zfs_old_snapshots': {
'mode': '0755',
},
2020-11-10 09:35:01 +00:00
"/usr/local/share/icinga/plugins/check_zfs_volumes": {
'mode': '0755',
'content_type': 'mako',
},
2020-11-10 09:35:01 +00:00
"/usr/local/share/icinga/plugins/check_zpool_online": {
'mode': '0755',
},
2020-11-10 09:35:01 +00:00
"/usr/local/share/icinga/plugins/check_zpool_space": {
'mode': '0755',
},
}
svc_systemd = {
2020-11-12 17:40:39 +00:00
'zfs-zed': {
2020-10-25 15:39:35 +00:00
'needs': {
'pkg_apt:zfs-zed'
},
},
}
zfs_datasets = node.metadata.get('zfs/datasets', {})
for name, attrs in node.metadata.get('zfs/pools', {}).items():
2021-08-17 16:09:51 +00:00
zfs_pools[name] = attrs
if node.os_version[0] > 10:
2021-08-17 16:09:51 +00:00
zfs_pools[name]['autotrim'] = attrs.get('autotrim', True)
directories = {
"/etc/zfs-snapshot-backup-pre.d": {
'purge': True,
},
"/etc/zfs-snapshot-backup-post.d": {
'purge': True,
},
}
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',
}