diff --git a/bundles/minecraft/items.py b/bundles/minecraft/items.py index 4c113b8..a672099 100644 --- a/bundles/minecraft/items.py +++ b/bundles/minecraft/items.py @@ -6,26 +6,51 @@ directories = { '/opt/minecraft': { 'owner': 'minecraft', }, + '/var/lib/minecraft': { + 'owner': 'minecraft', + }, } downloads = { '/opt/minecraft/server.jar': { 'url': node.metadata.get('minecraft/download'), 'sha256': node.metadata.get('minecraft/sha256'), - } -} - -files = { - '/opt/minecraft/eula.txt': { - 'content': 'eula=true', - } -} - -svc_systemd = { - 'minecraft': { 'needs': { - 'file:/opt/minecraft/eula.txt', - 'download:/opt/minecraft/server.jar', + 'directory:/opt/minecraft', }, - }, + } } + + +for name, properties in node.metadata.get('minecraft/servers').items(): + directories[f'/var/lib/minecraft/{name}'] = { + 'owner': 'minecraft', + } + + files[f'/var/opt/minecraft/{name}/eula.txt'] = { + 'content': 'eula=true', + 'owner': 'minecraft', + 'needed_by': { + f'svc_systemd:minecraft-{name}' + }, + 'triggers': { + f'svc_systemd:minecraft-{name}:restart' + }, + } + + translations = {True: 'true', False: 'false', None: ''} + files[f'/var/opt/minecraft/{name}/server.properties'] = { + 'content': '\n'.join( + f'{key}={translations.get(value, value)}' + for key, value in properties.items() + ), + 'owner': 'minecraft', + 'needed_by': { + f'svc_systemd:minecraft-{name}' + }, + 'triggers': { + f'svc_systemd:minecraft-{name}:restart' + }, + } + + svc_systemd[f'minecraft-{name}'] = {} diff --git a/bundles/minecraft/metadata.py b/bundles/minecraft/metadata.py index 727d077..ff8a20a 100644 --- a/bundles/minecraft/metadata.py +++ b/bundles/minecraft/metadata.py @@ -1,20 +1,96 @@ assert node.has_bundle('java') -defaults = { - 'systemd': { - 'units': { - 'minecraft.service': { - 'Unit': { - 'Description': 'minecraft', - 'After': 'network.target', - }, - 'Service': { - 'User': 'minecraft', - 'WorkingDirectory': '/opt/minecraft', - 'ExecStart': '/usr/bin/java -Xms1024M -Xmx2560M -jar /opt/minecraft/server.jar nogui', - 'Restart': 'always', - }, - }, - }, - }, +default_properties = { + 'broadcast-rcon-to-ops': True, + 'view-distance': 10, + 'enable-jmx-monitoring': False, + 'server-ip': None, + 'resource-pack-prompt': None, + 'rcon.port': 25251, + 'gamemode': 'survival', + 'server-port': 25250, + 'allow-nether': True, + 'enable-command-block': False, + 'enable-rcon': False, + 'sync-chunk-writes': True, + 'enable-query': False, + 'op-permission-level': 4, + 'prevent-proxy-connections': False, + 'resource-pack': None, + 'entity-broadcast-range-percentage': 100, + 'level-name': 'world', + 'rcon.password': None, + 'player-idle-timeout': 0, + 'motd': 'A Minecraft Server', + 'query.port': 25252, + 'force-gamemode': False, + 'rate-limit': 0, + 'hardcore': False, + 'white-list': False, + 'broadcast-console-to-ops': True, + 'pvp': True, + 'spawn-npcs': True, + 'spawn-animals': True, + 'snooper-enabled': True, + 'difficulty': 'easy', + 'function-permission-level': 2, + 'network-compression-threshold': 256, + 'text-filtering-config': None, + 'require-resource-pack': False, + 'spawn-monsters': True, + 'max-tick-time': 60000, + 'enforce-whitelist': False, + 'use-native-transport': True, + 'max-players': 20, + 'resource-pack-sha1': None, + 'spawn-protection': 0, + 'online-mode': True, + 'enable-status': True, + 'allow-flight': False, + 'max-world-size': 29999984, } + + +@metadata_reactor.provides( + 'minecraft/servers', +) +def server_properties(metadata): + servers = {} + + for name, options in metadata.get('minecraft/servers').items(): + servers[name] = { + **default_properties, + } + + return { + 'minecraft': { + 'servers': servers, + }, + } + + +@metadata_reactor.provides( + 'systemd/units', +) +def server_unitfiles(metadata): + units = {} + + for name in metadata.get('minecraft/servers'): + units[f'minecraft-{name}.service'] = { + 'Unit': { + 'Description': f'minecraft server {name}', + 'After': 'network.target', + }, + 'Service': { + 'User': 'minecraft', + 'WorkingDirectory': f'/var/lib/minecraft/{name}', + 'ExecStart': '/usr/bin/java -Xms1024M -Xmx2560M -jar /opt/minecraft/server.jar nogui', + 'Restart': 'always', + }, + } + + return { + 'systemd': { + 'units': units, + }, + } diff --git a/nodes/htz.games.py b/nodes/htz.games.py index 3226cbe..895dd19 100644 --- a/nodes/htz.games.py +++ b/nodes/htz.games.py @@ -28,6 +28,11 @@ 'minecraft': { 'download': 'https://launcher.mojang.com/v1/objects/a16d67e5807f57fc4e550299cf20226194497dc2/server.jar', 'sha256': 'e8c211b41317a9f5a780c98a89592ecb72eb39a6e475d4ac9657e5bc9ffaf55f', + 'servers': { + 'test1': { + 'rcon.password': '!decrypt:encrypt$gAAAAABhPyiZwNaanZ66yWGek-TXITmqQax1QU25hDgsRveJXe3AKKI6fP6f_XRvx1FZgixKMOaixgbgLcsJi_rY5IdZ5NZqIw==', + }, + }, }, }, }