swapfile
This commit is contained in:
parent
487899ae3e
commit
776e876876
5 changed files with 68 additions and 11 deletions
50
bundles/systemd-swap/items.py
Normal file
50
bundles/systemd-swap/items.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
size = node.metadata.get('systemd-swap/size')
|
||||
assert isinstance(size, int)
|
||||
|
||||
actions = {
|
||||
'stop_swap': {
|
||||
'command': f'systemctl stop swapfile.swap',
|
||||
'unless': f'rm /swapfile',
|
||||
'triggered': True,
|
||||
},
|
||||
'create_swapfile': {
|
||||
'command': f'dd if=/dev/zero of=/swapfile bs={size} count=1',
|
||||
'unless': f'stat -c %s /swapfile | grep ^{size}$',
|
||||
'preceded_by': {
|
||||
'action:stop_swap',
|
||||
},
|
||||
'triggers': {
|
||||
'action:initialize_swapfile',
|
||||
'svc_systemd:swapfile.swap:restart',
|
||||
},
|
||||
},
|
||||
'initialize_swapfile': {
|
||||
'command': f'mkswap /swapfile',
|
||||
'triggered': True,
|
||||
'needs': {
|
||||
'action:create_swapfile',
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
files = {
|
||||
'/swapfile': {
|
||||
'content_type': 'any',
|
||||
'mode': '600',
|
||||
'triggers': {
|
||||
'svc_systemd:swapfile.swap:restart',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
svc_systemd = {
|
||||
'swapfile.swap': {
|
||||
'preceded_by': {
|
||||
'action:initialize_swapfile',
|
||||
},
|
||||
'needs': {
|
||||
'action:systemd-reload',
|
||||
'action:create_swapfile',
|
||||
},
|
||||
},
|
||||
}
|
14
bundles/systemd-swap/metadata.py
Normal file
14
bundles/systemd-swap/metadata.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
defaults = {
|
||||
'systemd-swap': {
|
||||
'size': 2*10**9,
|
||||
},
|
||||
'systemd': {
|
||||
'units': {
|
||||
'swapfile.swap': {
|
||||
'Swap': {
|
||||
'What': '/swapfile',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
|
@ -18,7 +18,7 @@ for name, unit in node.metadata.get('systemd/units').items():
|
|||
'svc_systemd:systemd-networkd:restart',
|
||||
],
|
||||
}
|
||||
elif extension in ['timer', 'service', 'mount']:
|
||||
elif extension in ['timer', 'service', 'mount', 'swap']:
|
||||
path = f'/etc/systemd/system/{name}'
|
||||
dependencies = {
|
||||
'triggers': [
|
||||
|
|
|
@ -14,7 +14,7 @@ def units(metadata):
|
|||
for name, config in metadata.get('systemd/units').items():
|
||||
extension = name.split('.')[-1]
|
||||
|
||||
if extension not in ['timer', 'service', 'network', 'netdev', 'mount']:
|
||||
if extension not in ['timer', 'service', 'network', 'netdev', 'mount', 'swap']:
|
||||
raise Exception(f'unknown extension {extension}')
|
||||
|
||||
if not config.get('Install/WantedBy'):
|
||||
|
@ -47,7 +47,7 @@ def services(metadata):
|
|||
for name, config in metadata.get('systemd/services').items():
|
||||
extension = name.split('.')[-1]
|
||||
|
||||
if extension not in ['timer', 'service', 'mount']:
|
||||
if extension not in ['timer', 'service', 'mount', 'swap']:
|
||||
raise Exception(f'unknown extension: {extension}')
|
||||
|
||||
return {
|
||||
|
|
|
@ -10,17 +10,10 @@
|
|||
'zfs',
|
||||
'openhab',
|
||||
'java',
|
||||
'systemd-swap',
|
||||
],
|
||||
'metadata': {
|
||||
'FIXME_dont_touch_sshd': True,
|
||||
'telegraf': {
|
||||
'config': {
|
||||
'agent': {
|
||||
'flush_interval': '30s',
|
||||
'interval': '30s',
|
||||
},
|
||||
},
|
||||
},
|
||||
'id': '0afcde75-95c8-4fbd-b4c2-8a0fcc92884a',
|
||||
'network': {
|
||||
'internal': {
|
||||
|
|
Loading…
Reference in a new issue