I wanted to host Valheim[0] for my friends using a dedicated server on my home box. The server can be heavy, so I didn't want it running 24/7.<p>Systemd has a feature called "socket activation" where it listens to sockets on behalf of your service and then starts it up on-demand when there is traffic on the socket. Unfortunately Valheim's server does not support this, so a proxy must be used. Double unfortunately, the Systemd provided systemd-socket-proxyd[1] doesn't support UDP, which the game uses.<p>To resolve this, and half as a learning exercise, I wrote my own small UDP proxy[2]. It opens a socket to the Valheim server for every incoming client address/port combination, so that replies can be routed back to the originating client. I would have written it in Erlang (using Gleam), but Erlang is not currently able to use the socket provided by Systemd. Node.js was a pragmatic choice based on ease of installation/setup and familiarity with JavaScript and the APIs.<p>The proxy seems to be running smoothly, and the server is started and shut down automatically by Systemd (as the proxy shuts itself down after a period of inactivity). The only remaining problem currently is that the server takes too long to start in the eyes of the game client, and thus the first connection attempt will always fail. For a server between friends, this is a minor issue.<p>I have also written a more detailed post about the process on my blog[3] if someone happens to be interested, but this post already contains most of the important stuff.<p>[0] <a href="https://www.valheimgame.com" rel="nofollow">https://www.valheimgame.com</a><p>[1] <a href="https://man.archlinux.org/man/core/systemd/systemd-socket-proxyd.8.en" rel="nofollow">https://man.archlinux.org/man/core/systemd/systemd-socket-pr...</a><p>[2] <a href="https://git.ahlcode.fi/nicd/valproxy" rel="nofollow">https://git.ahlcode.fi/nicd/valproxy</a><p>[3] <a href="https://blog.nytsoi.net/2024/07/18/valheim-systemd-socket-activation" rel="nofollow">https://blog.nytsoi.net/2024/07/18/valheim-systemd-socket-ac...</a>