2020-08-29 19:10:59 +00:00
|
|
|
from json import dumps
|
|
|
|
from os.path import join
|
|
|
|
|
|
|
|
from bundlewrap.metadata import MetadataJSONEncoder
|
|
|
|
|
2020-10-31 09:11:15 +00:00
|
|
|
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:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
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',
|
|
|
|
},
|
|
|
|
'/etc/zfs-snapshot-config.json': {
|
|
|
|
'content': dumps(
|
|
|
|
node.metadata.get('zfs', {}).get('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': {
|
|
|
|
'svc_systemd:zed:restart'
|
|
|
|
},
|
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 = {
|
|
|
|
'zed': {
|
2020-10-25 15:39:35 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:zfs-zed'
|
|
|
|
},
|
2020-08-29 19:10:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_datasets = node.metadata.get('zfs', {}).get('datasets', {})
|
|
|
|
zfs_pools = {}
|
|
|
|
|
|
|
|
for name, attrs in node.metadata.get('zfs', {}).get('pools', {}).items():
|
|
|
|
zfs_pools[name] = attrs
|
|
|
|
|
|
|
|
# Not yet supported on debian buster
|
|
|
|
#actions[f'pool_{name}_enable_trim'] = {
|
|
|
|
# 'command': f'zpool set autotrim=on {name}',
|
|
|
|
# 'unless': f'zpool get autotrim -H -o value {name} | grep -q on',
|
|
|
|
# 'needs': [
|
|
|
|
# f'zfs_pool:{name}'
|
|
|
|
# ]
|
|
|
|
#}
|
|
|
|
|
|
|
|
directories = {
|
|
|
|
"/etc/zfs-snapshot-backup-pre.d": {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
"/etc/zfs-snapshot-backup-post.d": {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
"/etc/zfs-snapshot-backup-final.d": {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO implement when we start managing backups via bundlewrap
|
|
|
|
#if node.metadata.get('zfs', {}).get('snapshots', {}).get('backup', {}).get('enabled', True):
|
|
|
|
# directories["/mnt/zfs-snapshot-backup"] = {}
|
|
|
|
#
|
|
|
|
# files["/usr/local/sbin/zfs-backup-snapshot"] = {
|
|
|
|
# 'content_type': 'mako',
|
|
|
|
# 'context': {
|
|
|
|
# # Set by our own metadata processor, guaranteed to exist.
|
|
|
|
# 'filesystems': node.metadata['zfs']['snapshots']['backup']['filesystems_with_snapshot'],
|
|
|
|
# },
|
|
|
|
# 'mode': '0755',
|
|
|
|
# }
|
|
|
|
# files["/usr/local/sbin/zfs-backup-snapshot-unmount"] = {
|
|
|
|
# 'content_type': 'mako',
|
|
|
|
# 'context': {
|
|
|
|
# # Set by our own metadata processor, guaranteed to exist.
|
|
|
|
# 'filesystems': node.metadata['zfs']['snapshots']['backup']['filesystems_with_snapshot'],
|
|
|
|
# },
|
|
|
|
# 'mode': '0755',
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
#else:
|
|
|
|
# files["/mnt/zfs-snapshot-backup"] = {'delete': True}
|
|
|
|
|
|
|
|
# TODO when we start using telegraf
|
|
|
|
#if node.has_bundle('telegraf'):
|
|
|
|
# files['/etc/telegraf-zfs-dataset.conf'] = {
|
|
|
|
# 'content': dumps(
|
|
|
|
# node.metadata.get('zfs', {}),
|
|
|
|
# cls=MetadataJSONEncoder,
|
|
|
|
# indent=4,
|
|
|
|
# sort_keys=True,
|
|
|
|
# ) + '\n',
|
|
|
|
# }
|
|
|
|
# files['/usr/local/bin/telegraf-zfs-dataset'] = {
|
|
|
|
# 'mode': '0775',
|
|
|
|
# }
|