Minecraft Server Controll socket

I created a stdin interface for the Minecraft server. I build this to have a way to control the server (like giving someone op) via a command on the server, and not using rcon. This is built via a systemd socket. But with this way, I’m unsure, if it is too hacky to be upstreamed into nixpkgs.
my current solution is this.

Should I upstream it into nixpkgs?

3 Likes

As long as there’s a way to switch between rcon and the socket approach, I think it’s a nice option to add.
I’m still trying to find a nice way to add mods without having to rewrite the whole module myself… There’s no easy way to add things to the preStart.
Maybe while you’re at it, and you also want mods, it would be a nice thing to add. :slight_smile:

You can have both, my approach can also have rcon.

I will see if I have an idea to add mods. But I’m unsure how to patch to server.jar to read mods.

1 Like

I more or less gave up on trying to configure minecraft declaratively due to the complexity dealing with mods. I ended up just creating a module to start/stop/manage the minecraft server(s). The minecraft directory is then managed as normal.

It isn’t ideal but if you mod heavily, managing it declaratively becomes complicated. There isn’t always a universal way to keep the mods up to date and in some cases you may not even want to.

1 Like

I created a pr for the fifo thingy, and also added a warning system, to see when the server restarts.

I’m trying to find out, how to build a fabric server as an derivation, because the installer needs access to the maven. If I find a way, I will try to build a way to link mods inside the mod directory.

Allo,

I have started a minecraft server on nixos and I saw here that you can communicate to the server via systems sockets but I have never done that and I can’t find it on the internet how can I do that. So can you give me pointers on how to use it?

Greetings Evelyn

Ps: I am not sure if this is the correct thread to ask, I am new to this.

The configuration from this thread wasn’t merged upstream, so you will have to set it yourself.

I’ve not tested it, but if this configuration is correct, and assuming you’re using the NixOS module, you’ll need to put this in your configuration:

systemd.services.minecraft-server.serviceConfig.StandardInput = "socket";
systemd.services.minecraft-server.serviceConfig.StandardOutput = "journal";

systemd.sockets.minecraft-server = {
  description = "controll process for the minecraft server";
  socketConfig.ListenFIFO = "/run/minecraft/stdin";
  wantedBy = [ "sockets.target" ];
};

Then you can see the server logs using journalctl -f minecraft-server and write commands using e.g. echo 'op ShadowBooster' > /run/minecraft/stdin.

The alternative is just using the built-in rcon protocol: GitHub - Tiiffi/mcrcon: Rcon client for Minecraft

You may want to make sure the firewall port for it isn’t opened to the public, though.

1 Like