New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/minecraft-server: add fifo controll and stop warning #88432
Conversation
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/minecraft-server-controll-socket/7286/5 |
17bd691
to
1719c3d
Compare
Thanks, @infinisil. Applied all changes. |
Fixed, sorry missed it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the minor bits in the review, my only other concern is:
$ systemctl stop minecraft-server
Warning: Stopping minecraft-server.service, but it can still be activated by:
minecraft-server.socket
For what we use the socket for, I don't think it makes sense for it to be allowed to start the service. If there's no way to turn this off then I guess we'll just roll with it though.
The only way I see is to run a PostStop script which calls systemd to stop |
I wasn't really happy with the current solution, so I tried some alternate approaches, and I found one that works quite well: Instead of having systemd create the socket, let the minecraft service itself create it (and destroy it), then we don't need to deal with socket unit weirdness. And then just pipe the socket to the minecraft command. Here's the diff: diff --git a/nixos/modules/services/games/minecraft-server.nix b/nixos/modules/services/games/minecraft-server.nix
index c097e50b3e3..1f87557b630 100644
--- a/nixos/modules/services/games/minecraft-server.nix
+++ b/nixos/modules/services/games/minecraft-server.nix
@@ -161,6 +161,7 @@ in {
standardInputFifo = mkOption {
type = types.str;
+ readOnly = true;
default = "/run/minecraft/stdin";
description = ''
The path to a FIFO for sending commands to standard input of the
@@ -205,18 +206,24 @@ in {
description = "Minecraft Server Service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
- requires = [ "minecraft-server.socket" ];
serviceConfig = {
- ExecStart = "${cfg.package}/bin/minecraft-server ${cfg.jvmOpts}";
Restart = "always";
User = "minecraft";
+ # Allow group to write to created files
+ UMask = "0002";
WorkingDirectory = cfg.dataDir;
- StandardInput = "socket";
+ RuntimeDirectory = "minecraft";
StandardOutput = mkDefault "journal";
};
+ script = ''
+ ${cfg.package}/bin/minecraft-server ${cfg.jvmOpts} <>${cfg.standardInputFifo}
+ '';
+
preStart = ''
+ mkfifo ${cfg.standardInputFifo}
+
ln -sf ${eulaFile} eula.txt
'' + (if cfg.declarative then ''
@@ -245,25 +252,13 @@ in {
fi
'');
- preStop = let
+ preStop = let
script = pkgs.writeShellScript "minecraft-stop-commands" cfg.stopCommands;
in optionalString (cfg.stopCommands != null) ''
${script} > ${cfg.standardInputFifo}
'';
};
- systemd.sockets.minecraft-server = {
- description = "Minecraft stdin fifo file";
- socketConfig = {
- ListenFIFO = cfg.standardInputFifo;
- SocketUser = "minecraft";
- SocketGroup = "minecraft";
- SocketMode = "0660";
- };
- #wantedBy = [ "sockets.target" ];
-
- };
-
networking.firewall = mkIf cfg.openFirewall (if cfg.declarative then {
allowedUDPPorts = [ serverPort ];
allowedTCPPorts = [ serverPort ] Notes:
|
I marked this as stale due to inactivity. → More info |
Forgot about this, and currently not hosting a mc Server. Will close |
Did this ever get finished. |
Not past this state. So usable, but not clean enough to push it. Feel free to continue work on it, if you have questions feel free to ask |
Motivation for this change
Providing a way to control the Minecraft server without the use of rcon, or running the Minecraft server in a tmux session.
Also, be able to see when the server restarts when you are playing.
Things done
implement
services.minecraft-server.fifo
andservices.minecraft-server.warn
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)