diff --git a/bundles/l4d2/files/l4d2.service b/bundles/l4d2/files/l4d2.service deleted file mode 100644 index 06cc1fd..0000000 --- a/bundles/l4d2/files/l4d2.service +++ /dev/null @@ -1,13 +0,0 @@ -GNU nano 4.8 /etc/systemd/system/l4d2-server-a.service -[Unit] -Description=l4d2 Server A -After=network.target steam-update.service - -[Service] -User=steam -WorkingDirectory=/home/steam/steam/l4d2 -ExecStart=/home/steam/steam/l4d2/srcds_run -port 27001 -secure +exec server_a.cfg -Restart=on-failure - -[Install] -WantedBy=multi-user.target diff --git a/bundles/l4d2/files/update_addons b/bundles/l4d2/files/update_addons deleted file mode 100644 index 6025c5b..0000000 --- a/bundles/l4d2/files/update_addons +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -/home/steam/steam_workshop_downloader/workshop.py -o /home/steam/steam/l4d2/left4dead2/addons 2283884609 -chown -R steam:steam /home/steam/steam/l4d2/left4dead2/addons diff --git a/bundles/l4d2/metadata.py b/bundles/l4d2/metadata.py deleted file mode 100644 index 6c1b981..0000000 --- a/bundles/l4d2/metadata.py +++ /dev/null @@ -1,43 +0,0 @@ -defaults = { - 'steam': { - 'games': { - 'left4dead2': '222860', - }, - }, - 'left4dead2': { - 'serevrs': {}, - }, -} - - -@metadata_reactor.provides( - 'systemd/units', -) -def steam(metadata): - units = {} - services = {} - - for name, config in metadata.get('left4dead2/servers').items(): - units[f'left4dead2-server-{name}.service'] = { - 'Unit': { - 'Description': 'steam: install and update games', - 'After': 'network.target', - 'Requires': 'steam-update.service', - }, - 'Service': { - 'User': 'steam', - 'Group': 'steam', - 'WorkingDirectory': '/opt/left4dead2', - 'ExecStart': f'/opt/left4dead2/srcds_run -port {config["port"]} -secure +exec /etc/left4dead2/{name}.cfg', - 'Restart': 'on-failure', - }, - 'Install': { - 'WantedBy': ['multi-user.target'], - }, - } - - return { - 'systemd': { - 'units': units, - }, - } diff --git a/bundles/l4d2/README.md b/bundles/left4dead2/README.md similarity index 100% rename from bundles/l4d2/README.md rename to bundles/left4dead2/README.md diff --git a/bundles/l4d2/items.py b/bundles/left4dead2/items.py similarity index 54% rename from bundles/l4d2/items.py rename to bundles/left4dead2/items.py index ebb2843..7913f66 100644 --- a/bundles/l4d2/items.py +++ b/bundles/left4dead2/items.py @@ -1,10 +1,45 @@ directories = { + '/opt/left4dead2': { + 'owner': 'steam', + }, + '/opt/left4dead2/ems/admin system': { + 'owner': 'steam', + }, + '/opt/left4dead2/addons': { + 'owner': 'steam', + 'purge': True, + }, '/etc/left4dead2': { 'owner': 'steam', 'purge': True, + }, +} + +files = { + '/opt/left4dead2/ems/admin system/admins.txt': { + 'owner': 'steam', + 'content': '\n'.join(node.metadata.get('left4dead2/admins')), } } +svc_systemd = { + 'left4dead2-workshop': { + 'running': False, + 'needs': [ + 'svc_systemd:steam-update', + ], + }, +} + +for id in node.metadata.get('left4dead2/workshop'): + directories[f'/opt/left4dead2/addons/{id}'] = { + 'owner': 'steam', + 'triggers': [ + 'svc_systemd:left4dead2-workshop:restart', + ], + } + +server_units = set() for name, config in node.metadata.get('left4dead2/servers').items(): config.pop('port') config['sv_steamgroup'] = name @@ -25,12 +60,22 @@ for name, config in node.metadata.get('left4dead2/servers').items(): f'file:/etc/systemd/system/left4dead2-server-{name}.service', ], } + server_units.add(f'left4dead2-server-{name}') + + +for id in node.metadata.get('left4dead2/workshop'): + directories[f'/opt/left4dead2/addons/{id}'] = { + 'owner': 'steam', + 'triggers': [ + 'svc_systemd:left4dead2-workshop:restart', + ], + } # TIDYUP find_obsolete_units = ( 'find /etc/systemd/system -type f -name "left4dead2-server-*.service" ' + - ' '.join(f"! -name '{service}.service'" for service in svc_systemd) + ' '.join(f"! -name '{name}.service'" for name in server_units) ) actions['remove_obsolete_left4dead2_units'] = { 'command': ( diff --git a/bundles/left4dead2/metadata.py b/bundles/left4dead2/metadata.py new file mode 100644 index 0000000..8362658 --- /dev/null +++ b/bundles/left4dead2/metadata.py @@ -0,0 +1,89 @@ +assert node.has_bundle('steam') + +from shlex import quote + +defaults = { + 'steam': { + 'games': { + 'left4dead2': '222860', + }, + }, + 'left4dead2': { + 'servers': {}, + 'admins': set(), + 'workshop': set(), + }, +} + + +@metadata_reactor.provides( + 'systemd/units', +) +def workshop(metadata): + command = ( + 'set -x; ' + 'for ID in ' + ' '.join(metadata.get('left4dead2/workshop')) + '; ' + 'do ' + 'if ! ls /opt/left4dead2/addons/$ID/*.vpk; ' + 'then ' + 'cd /opt/left4dead2/addons/$ID; ' + '/opt/steam-workshop-downloader https://steamcommunity.com/sharedfiles/filedetails\?id\=$ID; ' + 'unzip $ID.zip; ' + 'fi; ' + 'done' + ) + + return { + 'systemd': { + 'units': { + 'left4dead2-workshop.service': { + 'Unit': { + 'Description': 'install workshop items', + 'After': 'network.target', + 'Requires': 'steam-update.service', + 'PartOf': 'steam-update.service' + }, + 'Service': { + 'Type': 'oneshot', + 'User': 'steam', + 'ExecStart': f'/bin/bash -c {quote(command)}', + }, + 'Install': { + 'WantedBy': ['multi-user.target'], + }, + } + } + } + } + + +@metadata_reactor.provides( + 'systemd/units', +) +def server_units(metadata): + units = {} + + for name, config in metadata.get('left4dead2/servers').items(): + units[f'left4dead2-server-{name}.service'] = { + 'Unit': { + 'Description': f'left4dead2 server {name}', + 'After': 'network.target', + 'Requires': 'steam-update.service', + }, + 'Service': { + 'User': 'steam', + 'Group': 'steam', + 'WorkingDirectory': '/opt/left4dead2', + 'ExecStart': f'/opt/left4dead2/srcds_run -port {config["port"]} -secure +exec /etc/left4dead2/{name}.cfg', + 'Restart': 'on-failure', + }, + 'Install': { + 'WantedBy': ['multi-user.target'], + }, + } + + return { + 'systemd': { + 'units': units, + }, + } diff --git a/bundles/steam/files/steam-update.service b/bundles/steam/files/steam-update.service deleted file mode 100644 index b2d975d..0000000 --- a/bundles/steam/files/steam-update.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=l4d2 update -After=network.target - -[Service] -Type=oneshot -User=steam -Group=steam -WorkingDirectory=/home/steam/steam -ExecStart=/home/steam/steam_workshop_downloader/workshop.py -o /home/steam/steam/l4d2/left4dead2/addons/workshop 2283884609 -ExecStart=/home/steam/steam/steamcmd.sh +login anonymous +force_install_dir ./l4d2/ +app_update 222860 validate +quit - -[Install] -WantedBy=multi-user.target diff --git a/bundles/steam/items.py b/bundles/steam/items.py index cb5bdd2..e004419 100644 --- a/bundles/steam/items.py +++ b/bundles/steam/items.py @@ -18,6 +18,13 @@ files = { 'owner': 'steam', 'group': 'steam', }, + '/opt/steam-workshop-downloader': { + 'content_type': 'download', + 'source': 'https://github.com/SegoCode/swd/releases/download/1.1/swd-linux-amd64', + 'owner': 'steam', + 'group': 'steam', + 'mode': '750', + }, } actions = { @@ -37,5 +44,9 @@ actions = { }, } -# sudo -Hiu steam bash -c '~/steam/steamcmd.sh +login anonymous +force_install_dir ./l4d2/ +app_update 222860 validate +quit' -# https://github.com/SegoCode/swd/releases/download/1.1/swd-linux-amd64 +svc_systemd['steam-update'] = { + 'running': False, + 'needs': { + 'file:/etc/systemd/system/steam-update.service', + } +} diff --git a/nodes/htz.games-2.py b/nodes/htz.games-2.py index 9020dc8..d07fa22 100644 --- a/nodes/htz.games-2.py +++ b/nodes/htz.games-2.py @@ -7,7 +7,7 @@ ], 'bundles': [ 'steam', - 'l4d2', + 'left4dead2', # 'java', # 'minecraft', ], @@ -15,6 +15,12 @@ 'id': '3915f236-dd0a-4c6c-8fb3-1584c81038c6', 'left4dead2': { 'steamgroups': [38347879], + 'workshop': { + '2524204971', # admin system inkl admin menu + }, + 'admins': { + 'STEAM_1:0:12376499', # CroneKorkN + }, 'servers': { 'realism-expert2': { 'port': 27001, diff --git a/nodes/htz.games.py b/nodes/htz.games.py index 827edc9..022f3d4 100644 --- a/nodes/htz.games.py +++ b/nodes/htz.games.py @@ -7,7 +7,7 @@ ], 'bundles': [ # 'steam', -# 'l4d2', +# 'left4dead2', 'java', # 'minecraft', ],