Running hedgewars-server with systemd socket activation via systemd-socket-proxyd

No replies
die_mensch_maschine
User offline. Last seen 4 weeks 1 day ago. Offline
Joined: 2024-08-02
Posts: 1

Hello everyone. Didn't find this mentioned anywhere on the site, so I thought I should document this here if it would be useful.

My scenario is as follows: I run a dedicated server for me and my friends on a separate headless Linux machine, and if I configure it to run just as a normal systemd unit, after a certain amount of uptime it starts to behave erratically/drop connections, so I have to restart it manually or just ignore it and run the server from within the client GUI each time we congregate to play. Neither of which is a very convenient way for me. So I devised a different scheme, which goes like this:

In /etc/systemd/system, create files as follows:

# cat hedgewars-server.service 
[Unit]
Description=Hedgewars server
StopWhenUnneeded=true

[Service]
ExecStart=/usr/lib/hedgewars/bin/hedgewars-server -d True -p 33146
User=games
PrivateNetwork=yes
PrivateTmp=yes
ExecStartPost=/bin/sleep 7

# cat proxy-to-hedgewars-server.service 
[Unit]
BindsTo=proxy-to-hedgewars-server.socket
After=proxy-to-hedgewars-server.socket
JoinsNamespaceOf=hedgewars-server.service
BindsTo=hedgewars-server.service
After=hedgewars-server.service

[Service]
Type=notify
ExecStart=/usr/lib/systemd/systemd-socket-proxyd --exit-idle-time=1m 127.0.0.1:33146
PrivateTmp=yes
PrivateNetwork=yes

# cat proxy-to-hedgewars-server.socket 
[Socket]
ListenStream=0.0.0.0:46631

[Install]
WantedBy=sockets.target

Be careful, the last two files must have the same name (or you can specify the service-file name in the socket-file, but it's easier to keep them same).

And after that, execute

systemctl enable --now proxy-to-hedgewars-server.socket 

Which should start listening on the default hedgewars server port on your machine and when a client connects, it will start the server (with a bit of a delay so that client doesn't disconnect prematurely), all the connections would be proxied to the server, and when the session is over and everybody has disconnected the server will automatically be shut down after the specified timeout.

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]