From ef6ccc2a6c9944897f8f40b95988930ada2e9206 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Fri, 26 Jul 2024 04:12:32 -0700 Subject: [PATCH] feat: restart minecraft server daily at 5:00 AM --- configuration.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/configuration.nix b/configuration.nix index f03bde8..8bd4b2b 100644 --- a/configuration.nix +++ b/configuration.nix @@ -134,6 +134,23 @@ # Enable the OpenSSH daemon. services.openssh.enable = true; + systemd.services.restart-minecraft-server = { + description = "Restarts minecraft server docker container"; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.docker}/bin/docker restart minecraft-server-mc-1"; + }; + }; + + systemd.timers.restart-minecraft-server = { + description = "Restart minecraft server daily"; + timerConfig = { + OnCalendar = "*-*-* 05:00:00"; + Persistent = true; + }; + wantedBy = [ "timers.target" ]; + }; + # Open ports in the firewall. networking.firewall.allowedTCPPorts = [ 2222 ]; networking.firewall.allowedUDPPorts = [ 2222 ]; @@ -163,6 +180,5 @@ # # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion . system.stateVersion = "24.11"; # Did you read the comment? - }