Profile
This is the most Important Thing to do in this Setup Systemd is used to create an Minecraft server that will start automatically and stop when there is no player Written by Solene on 20 August 2022. Tags: #minecraft #nixos #systemd #automation Introduction to the SS Sometimes, I think I have specific needs that I have to resolve on my own. Today, I decided to set up a local Minecraft server running on my own workstation however, only when someone needed it. The point was that instead of having a big java server running all the system, Minecraft server would start when a user connected and then stop when there was no connection from a player. However, after looking a bit more into this topic it appears that I'm not the only one to need this. on-demand-minecraft is a project that automatically starts an online cloud server for gamers who are whitelisted. minecraft-server-hibernation: a wrapper that starts and stop a Minecraft server upon condition As often, I prefer not to rely on third party tools when I can therefore, I came across an alternative to do this with only systemd. Also, take keep in mind that this technique can work with any daemon as long as you programmatically receive the information whether to let it run or stop. In this case I'm using Minecraft and the server's stops in accordance with the player's to the server via the rcon (a remote administration protocol). The setup SS To illustrate the dependencies I created a simple graph. There are many system-wide components that are involved in this. The most important thing is the use of the systemd proxyifier, it's a command that accepts a connection over TCP and relay it to a different socket, meanwhile you can start things like an server and waiting for it to be ready. This is the most crucial element of this configuration. Without it, this wouldn't be possible. Basically, listen-minecraft.socket listens on the public TCP port and runs listen-minecraft.service upon connection. This service needs hook-minecraft.service which is responsible for stopping or starting minecraft, but will also make listen-minecraft.service wait for the TCP port to be open so the proxifier will relay the connection to the daemon. Then, minecraft-server.service is started alongside with stop-minecraft.timer which will regularly run stop-minecraft.service to try to stop the server if possible. Configuration SS To configure my on-demand Minecraft server I used NixOS. free This is something you could do with any systemd compatible device, but if I provide a NixOS example. It should not be difficult to translate into regular systemd configuration files. Conclusion SS
Forum Role: Participant
Topics Started: 0
Replies Created: 0