left4dead unit dependencies

This commit is contained in:
cronekorkn 2022-12-03 16:50:45 +01:00
parent ccb6dcd14f
commit daf582d6d8
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
4 changed files with 68 additions and 50 deletions

View file

@ -37,57 +37,40 @@ def rconn_password(metadata):
'steam-workshop-download',
)
def workshop_download(metadata):
if not metadata.get('left4dead2/workshop'):
return {}
result = {
'left4dead-global': {
if metadata.get('left4dead2/workshop'):
return {
'steam-workshop-download': {
'left4dead2-global': {
'ids': metadata.get('left4dead2/workshop'),
'path': '/opt/steam/left4dead2/left4dead2/addons',
'user': 'steam',
'requires': {
'steam.target',
},
'required_by': {
f'left4dead2-{name}.service'
for name in metadata.get('left4dead2/servers')
},
},
},
}
for name, config in metadata.get('left4dead2/servers').items():
if 'workshop' in config:
result[f'left4dead2-{name}'] = {
'ids': config['workshop'],
'path': f'/opt/steam/left4dead2-servers/{name}/left4dead2/addons',
'user': 'steam',
}
return {
'steam-workshop-download': result,
}
else:
return {}
@metadata_reactor.provides(
'steam-workshop-download',
'systemd/units',
)
def server_units(metadata):
units = {}
workshop = {}
for name, config in metadata.get('left4dead2/servers').items():
units[f'left4dead2-{name}.service'] = {
'Unit': {
'Description': f'left4dead2 server {name}',
'After': {'steam.target'},
},
'Service': {
'User': 'steam',
'Group': 'steam',
'WorkingDirectory': f'/opt/steam/left4dead2-servers/{name}',
'ExecStart': f'/opt/steam/left4dead2-servers/{name}/srcds_run -port {config["port"]} +exec server.cfg',
'Restart': 'on-failure',
},
'Install': {
'WantedBy': {'multi-user.target'},
},
}
# mount overlay
mountpoint = f'/opt/steam/left4dead2-servers/{name}'
formatted_name = mountpoint[1:].replace('-', '\\x2d').replace('/', '-') + '.mount'
units[formatted_name] = {
mount_unit_name = mountpoint[1:].replace('-', '\\x2d').replace('/', '-') + '.mount'
units[mount_unit_name] = {
'Unit': {
'Description': f"Mount left4dead2 server {name} overlay",
'Conflicts': 'umount.target',
@ -105,13 +88,47 @@ def server_units(metadata):
]),
},
'Install': {
'WantedBy': {
'multi-user.target',
'RequiredBy': {
f'left4dead2-{name}.service',
},
},
}
# individual workshop
if 'workshop' in config:
workshop[f'left4dead2-{name}'] = {
'ids': config['workshop'],
'path': f'/opt/steam/left4dead2-servers/{name}/left4dead2/addons',
'user': 'steam',
'requires': {
mount_unit_name,
},
'required_by': {
f'left4dead2-{name}.service',
},
}
# left4dead2 server unit
units[f'left4dead2-{name}.service'] = {
'Unit': {
'Description': f'left4dead2 server {name}',
'After': {'steam.target'},
'Requires': {'steam.target'},
},
'Service': {
'User': 'steam',
'Group': 'steam',
'WorkingDirectory': f'/opt/steam/left4dead2-servers/{name}',
'ExecStart': f'/opt/steam/left4dead2-servers/{name}/srcds_run -port {config["port"]} +exec server.cfg',
'Restart': 'on-failure',
},
'Install': {
'WantedBy': {'multi-user.target'},
},
}
return {
'steam-workshop-download': workshop,
'systemd': {
'units': units,
},

View file

@ -21,6 +21,7 @@ def workshop(metadata):
'steam-update.target',
},
'Before': 'steam.target',
'Requires': conf['requires'],
},
'Service': {
'Type': 'oneshot',
@ -28,7 +29,7 @@ def workshop(metadata):
'ExecStart': f"/opt/steam-workshop-download {' '.join(quote(str(id)) for id in conf['ids'])} --out {quote(conf['path'])}",
},
'Install': {
'WantedBy': {'multi-user.target'},
'RequiredBy': conf['required_by'],
},
}

View file

@ -54,7 +54,7 @@ def initial_unit(metadata):
}
},
'Install': {
'WantedBy': {'multi-user.target'},
'RequiredBy': {'steam.target'},
},
},
},

View file

@ -79,12 +79,12 @@
'standard': {
'port': 27020,
},
'standard-2': {
'port': 27021,
'workshop': {
#2256379828, # bhop detect
},
},
# 'standard-2': {
# 'port': 27021,
# 'workshop': {
# #2256379828, # bhop detect
# },
# },
},
'admins': {
'STEAM_1:0:12376499', # CroneKorkN ☮UKRAINE❤