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