Compare commits
5 commits
226b152fa0
...
426f37f098
Author | SHA1 | Date | |
---|---|---|---|
426f37f098 | |||
22d92af61b | |||
67d6e77ccf | |||
6621459820 | |||
b6cfc84e86 |
3 changed files with 55 additions and 54 deletions
|
@ -1,58 +1,10 @@
|
||||||
size = node.metadata.get('systemd-swap')
|
|
||||||
|
|
||||||
actions = {
|
|
||||||
'stop_swap': {
|
|
||||||
'command': f'systemctl stop swapfile.swap',
|
|
||||||
'unless': f'! systemctl is-active swapfile.swap',
|
|
||||||
'triggered': True,
|
|
||||||
},
|
|
||||||
'remove_swapfile': {
|
|
||||||
'command': f'rm /swapfile',
|
|
||||||
'unless': f'! test -e /swapfile',
|
|
||||||
'triggered': True,
|
|
||||||
'needs': {
|
|
||||||
'action:stop_swap',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'create_swapfile': {
|
|
||||||
'command': f'fallocate -l {size} /swapfile',
|
|
||||||
'unless': f'stat -c %s /swapfile | grep ^{size}$',
|
|
||||||
'preceded_by': {
|
|
||||||
'action:stop_swap',
|
|
||||||
'action:remove_swapfile',
|
|
||||||
},
|
|
||||||
'triggers': {
|
|
||||||
'action:initialize_swapfile',
|
|
||||||
'svc_systemd:swapfile.swap:restart',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'swapfile_mode': {
|
|
||||||
'command': f'chmod 600 /swapfile',
|
|
||||||
'unless': f'stat -c "%a" /swapfile | grep -q "^600$"',
|
|
||||||
'needs': {
|
|
||||||
'action:create_swapfile',
|
|
||||||
},
|
|
||||||
'triggers': {
|
|
||||||
'svc_systemd:swapfile.swap:restart',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'initialize_swapfile': {
|
|
||||||
'command': f'mkswap /swapfile',
|
|
||||||
'triggered': True,
|
|
||||||
'needs': {
|
|
||||||
'action:swapfile_mode',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
svc_systemd = {
|
svc_systemd = {
|
||||||
|
'swapfile-prepare.service': {
|
||||||
|
'running': None,
|
||||||
|
},
|
||||||
'swapfile.swap': {
|
'swapfile.swap': {
|
||||||
'preceded_by': {
|
'needs': [
|
||||||
'action:initialize_swapfile',
|
'svc_systemd:swapfile-prepare.service',
|
||||||
},
|
],
|
||||||
'needs': {
|
|
||||||
'action:initialize_swapfile',
|
|
||||||
'action:systemd-reload',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,58 @@ defaults = {
|
||||||
'systemd': {
|
'systemd': {
|
||||||
'units': {
|
'units': {
|
||||||
'swapfile.swap': {
|
'swapfile.swap': {
|
||||||
|
'Unit': {
|
||||||
|
'PartOf': {
|
||||||
|
'swapfile-prepare.service', # restart together
|
||||||
|
},
|
||||||
|
},
|
||||||
'Swap': {
|
'Swap': {
|
||||||
'What': '/swapfile',
|
'What': '/swapfile',
|
||||||
},
|
},
|
||||||
|
'Install': {
|
||||||
|
'WantedBy': {
|
||||||
|
'swap.target',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@metadata_reactor.provides(
|
||||||
|
'systemd/units/swapfile.swap',
|
||||||
|
)
|
||||||
|
def unit(metadata):
|
||||||
|
size = metadata.get('systemd-swap')
|
||||||
|
|
||||||
|
return {
|
||||||
|
'systemd': {
|
||||||
|
'units': {
|
||||||
|
'swapfile-prepare.service': {
|
||||||
|
'Unit': {
|
||||||
|
'Before': {
|
||||||
|
'swapfile.swap',
|
||||||
|
},
|
||||||
|
'PartOf': {
|
||||||
|
'swapfile.swap', # restart together
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'Service': {
|
||||||
|
'Type': 'oneshot',
|
||||||
|
'ExecStartPre': [
|
||||||
|
'-/bin/rm /swapfile -f',
|
||||||
|
f'/bin/fallocate -l {size} /swapfile',
|
||||||
|
'/bin/chmod 600 /swapfile',
|
||||||
|
],
|
||||||
|
'ExecStart': '/usr/sbin/mkswap /swapfile',
|
||||||
|
},
|
||||||
|
'Install': {
|
||||||
|
'RequiredBy': {
|
||||||
|
'swapfile.swap',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ order = [
|
||||||
'Unit',
|
'Unit',
|
||||||
'Timer',
|
'Timer',
|
||||||
'Service',
|
'Service',
|
||||||
|
'Swap',
|
||||||
'Install',
|
'Install',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue