from json import dumps java_opts = set() for k, v in node.metadata.get('minecraft/java_opts').items(): if v is None: java_opts.add(k) else: java_opts.add(f'{k}={v}') directories['/home/minecraft/world'] = { 'owner': 'minecraft', 'group': 'minecraft', } directories['/home/minecraft/world_nether'] = { 'owner': 'minecraft', 'group': 'minecraft', } directories['/home/minecraft/world_the_end'] = { 'owner': 'minecraft', 'group': 'minecraft', } files['/usr/local/lib/systemd/system/minecraft.service'] = { 'content_type': 'mako', 'context': { 'java_opts': ' '.join(sorted(java_opts)), }, 'triggers': { 'action:systemd-reload', 'svc_systemd:minecraft:restart', }, } files['/home/minecraft/eula.txt'] = { 'content': 'eula=true\n', } files['/home/minecraft/server.properties'] = { # get it from data/minecraft/files/{node.name} 'source': node.name, } version, build_nr = node.metadata.get('minecraft/version') files['/home/minecraft/minecraft_server.jar'] = { 'content_type': 'download', 'source': f'https://api.papermc.io/v2/projects/paper/versions/{version}/builds/{build_nr}/downloads/paper-{version}-{build_nr}.jar', 'content_hash': node.metadata.get('minecraft/sha1', None), } svc_systemd['minecraft'] = { 'needs': { 'directory:/home/minecraft/world', 'directory:/home/minecraft/world_nether', 'directory:/home/minecraft/world_the_end', 'file:/home/minecraft/eula.txt', 'file:/home/minecraft/minecraft_server.jar', 'file:/home/minecraft/server.properties', 'file:/usr/local/lib/systemd/system/minecraft.service', 'pkg_apt:openjdk-17-jre', }, } files['/home/minecraft/ops.json'] = { 'content': dumps( [ { 'uuid': uuid, 'name': name, 'level': 4 } for name, uuid in sorted(node.metadata.get('minecraft/ops', {}).items()) ], indent=4, ) } if node.metadata.get('minecraft/allowlist', {}): files['/home/minecraft/whitelist.json'] = { 'content': dumps( [ { 'uuid': uuid, 'name': name, } for name, uuid in sorted(node.metadata.get('minecraft/allowlist').items()) ], indent=4, ) }