Compare commits
2 commits
426f37f098
...
226b152fa0
Author | SHA1 | Date | |
---|---|---|---|
226b152fa0 | |||
4e9c6bf67b |
2 changed files with 55 additions and 50 deletions
|
@ -1,10 +1,58 @@
|
|||
svc_systemd = {
|
||||
'swapfile-prepare.service': {
|
||||
'running': None,
|
||||
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 = {
|
||||
'swapfile.swap': {
|
||||
'preceded_by': {
|
||||
'action:initialize_swapfile',
|
||||
},
|
||||
'needs': {
|
||||
'action:initialize_swapfile',
|
||||
'action:systemd-reload',
|
||||
},
|
||||
'swapfile.swap': {
|
||||
'needs': [
|
||||
'svc_systemd:swapfile-prepare.service',
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -3,11 +3,6 @@ defaults = {
|
|||
'systemd': {
|
||||
'units': {
|
||||
'swapfile.swap': {
|
||||
'Unit': {
|
||||
'PartOf': {
|
||||
'swapfile-prepare.service', # restart together
|
||||
},
|
||||
},
|
||||
'Swap': {
|
||||
'What': '/swapfile',
|
||||
},
|
||||
|
@ -20,41 +15,3 @@ defaults = {
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@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',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue