From acb792f0a498364c8529c7d9671cf6ab6c59b39a Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sun, 10 Oct 2021 21:47:35 +0200 Subject: [PATCH] wip --- bundles/l4d2/items.py | 37 ++++++++++++++++++++++++++++++++----- bundles/l4d2/metadata.py | 6 ++++-- nodes/htz.games-2.py | 10 ++++++++-- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/bundles/l4d2/items.py b/bundles/l4d2/items.py index 46b11d8..ebb2843 100644 --- a/bundles/l4d2/items.py +++ b/bundles/l4d2/items.py @@ -5,17 +5,44 @@ directories = { } } -for name, config in node.metadata.get('left4dead2').items(): +for name, config in node.metadata.get('left4dead2/servers').items(): config.pop('port') + config['sv_steamgroup'] = name config['hostname'] = name - + config['sv_steamgroup'] = ','.join(str(gid) for gid in node.metadata.get('left4dead2/steamgroups')) + files[f'/etc/left4dead2/{name}.cfg'] = { 'content': '\n'.join( - f'{key} "{value}"' for key, value in config.items() - ), + f'{key} "{value}"' for key, value in sorted(config.items()) + ) + '\n', 'owner': 'steam', 'triggers': [ f'svc_systemd:left4dead2-server-{name}:restart', ], } - svc_systemd[f'left4dead2-server-{name}'] = {} + svc_systemd[f'left4dead2-server-{name}'] = { + 'needs': [ + f'file:/etc/systemd/system/left4dead2-server-{name}.service', + ], + } + +# TIDYUP + +find_obsolete_units = ( + 'find /etc/systemd/system -type f -name "left4dead2-server-*.service" ' + + ' '.join(f"! -name '{service}.service'" for service in svc_systemd) +) +actions['remove_obsolete_left4dead2_units'] = { + 'command': ( + f'for unitfile in $({find_obsolete_units}); ' + f'do ' + f'systemctl stop $(basename "$unitfile"); ' + f'systemctl disable $(basename "$unitfile"); ' + f'rm "$unitfile"; ' + f'systemctl daemon-reload; ' + f'done' + ), + 'unless': ( + find_obsolete_units + " | wc -l | grep -q '^0$'" + ), +} diff --git a/bundles/l4d2/metadata.py b/bundles/l4d2/metadata.py index b9d74fa..6c1b981 100644 --- a/bundles/l4d2/metadata.py +++ b/bundles/l4d2/metadata.py @@ -4,7 +4,9 @@ defaults = { 'left4dead2': '222860', }, }, - 'servers': {}, + 'left4dead2': { + 'serevrs': {}, + }, } @@ -15,7 +17,7 @@ def steam(metadata): units = {} services = {} - for name, config in metadata.get('left4dead2').items(): + for name, config in metadata.get('left4dead2/servers').items(): units[f'left4dead2-server-{name}.service'] = { 'Unit': { 'Description': 'steam: install and update games', diff --git a/nodes/htz.games-2.py b/nodes/htz.games-2.py index fe0e2d7..9020dc8 100644 --- a/nodes/htz.games-2.py +++ b/nodes/htz.games-2.py @@ -14,8 +14,14 @@ 'metadata': { 'id': '3915f236-dd0a-4c6c-8fb3-1584c81038c6', 'left4dead2': { - 'realism-expert': { - 'port': 27001, + 'steamgroups': [38347879], + 'servers': { + 'realism-expert2': { + 'port': 27001, + }, + 'realism-expert3': { + 'port': 27002, + }, } }, 'network': {