Number of fixes
Check / Lint Ansible Files (push) Successful in 1m40s

Package IONOS-DynDNS repository

Fix spigot-server's ExecStop

Enable Firewall but allow port 25565
This commit is contained in:
2023-11-18 13:44:10 +01:00
parent 8e0c6266af
commit 9b622e6e3e
5 changed files with 76 additions and 16 deletions
+9 -5
View File
@@ -55,6 +55,9 @@
# $ nix search wget
environment.systemPackages = with pkgs; [
vim
tmux
bottom
(pkgs.callPackage ../packages/ionos-dyndns.nix {})
];
# List services that you want to enable:
@@ -78,14 +81,15 @@
enable = true;
};
# TODO: ddclient + a nice domain
# DynDNS stuff. IONOS has a (proprietary?) API for this,
# so we're using a Python script from the interwebs :shrug:
# TODO: Config using agenix
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
networking.firewall.allowedTCPPorts = [ 25565 ];
networking.firewall.allowedUDPPorts = [ 25565 ];
# Or disable the firewall altogether.
# TODO: Only enable minecraft outside
networking.firewall.enable = false;
# networking.firewall.enable = false;
# TODO: Backups
+1 -1
View File
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
nixos-rebuild -I nixos-config=configuration.nix --target-host 192.168.0.206 --use-remote-sudo switch
nixos-rebuild -I nixos-config=configuration.nix --target-host gilgamesh --use-remote-sudo switch
+37 -9
View File
@@ -1,6 +1,7 @@
{ config, lib, pkgs, ... }:
with lib;
let
ionos-dyndns = pkgs.callPackage ../packages/ionos-dyndns.nix {};
spigot-server = pkgs.callPackage ../packages/spigot-server.nix {};
cfg = config.services.spigot;
name = "spigot";
@@ -39,16 +40,43 @@ in {
};
};
systemd.services.spigot-server = rec {
description = "Spigot Minecraft server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
User = "${cfg.user}";
systemd = {
services.spigot-server = {
description = "Spigot Minecraft server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
User = "${cfg.user}";
inherit StateDirectory;
WorkingDirectory = "/var/lib/${StateDirectory}";
ExecStart = "${spigot-server}/bin/spigot-server";
Sockets = "spigot-server.socket";
StandardInput = "socket";
StandardOutput = "journal";
StandardError = "journal";
inherit StateDirectory;
WorkingDirectory = "/var/lib/${StateDirectory}";
ExecStart = "${spigot-server}/bin/spigot-server -nogui";
ExecStop = [
"${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/echo save-all > /run/spigot-server.stdin'"
"${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/echo stop > /run/spigot-server.stdin'"
# Wait for the main process to exit
# If we don't do this systemd tries to nudge Java to stop, causing a race condition
# that leads to an ungraceful shutdown
"${pkgs.coreutils}/bin/echo \"Waiting for \${MAINPID} to exit...\""
"${pkgs.bash}/bin/bash -c 'while ${pkgs.coreutils}/bin/kill -s 0 $MAINPID 2>/dev/null; do sleep 0.5; done'"
];
};
};
sockets.spigot-server = {
description = "Spigot Minecraft server socket for commands and stuff";
unitConfig = {
# Automatically start and stop socket along with the service
PartOf = "spigot-server.service";
};
socketConfig = {
ListenFIFO = "/run/spigot-server.stdin";
};
};
};
};