From 889b866c82e6ce965a12bb390782db46259d06db Mon Sep 17 00:00:00 2001 From: Charles Duffy Date: Thu, 2 Oct 2025 10:41:29 -0500 Subject: [PATCH] nixos/nats: Shut down gracefully, and prevent automatic restart on deliberate stop SIGUSR2 puts nats-server into "lame-duck mode", where the node hands off leader roles and hands clients off to other nodes. --- nixos/modules/services/networking/nats.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/nats.nix b/nixos/modules/services/networking/nats.nix index 57765c9d2449..4508fdc1f339 100644 --- a/nixos/modules/services/networking/nats.nix +++ b/nixos/modules/services/networking/nats.nix @@ -138,7 +138,15 @@ in Type = "simple"; ExecStart = "${pkgs.nats-server}/bin/nats-server -c ${configFile}"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; - ExecStop = "${pkgs.coreutils}/bin/kill -SIGINT $MAINPID"; + + KillMode = "mixed"; + KillSignal = "SIGUSR2"; + SuccessExitStatus = [ + 0 + "SIGUSR2" + ]; + + TimeoutStopSec = "150"; # must exceed lame_duck_duration, which defaults to 2min Restart = "on-failure"; User = cfg.user;