bundlewrap/bundles/systemd-swap/metadata.py

52 lines
1.4 KiB
Python

defaults = {
'systemd-swap': 2*10**9,
'systemd': {
'units': {
'swapfile.swap': {
'Swap': {
'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',
},
},
'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',
},
},
},
},
},
}