This commit is contained in:
mwiegand 2021-10-10 23:16:23 +02:00
parent acb792f0a4
commit af592c771e
10 changed files with 156 additions and 79 deletions

View file

@ -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

View file

@ -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

View file

@ -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,
},
}

View file

@ -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': (

View file

@ -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,
},
}

View file

@ -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

View file

@ -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',
}
}

View file

@ -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,

View file

@ -7,7 +7,7 @@
],
'bundles': [
# 'steam',
# 'l4d2',
# 'left4dead2',
'java',
# 'minecraft',
],