From 8bf408f553dce51db28bca06f21b5a6e9128563e Mon Sep 17 00:00:00 2001 From: Patryk Wychowaniec Date: Wed, 1 Apr 2026 21:38:57 +0200 Subject: [PATCH] nixos/unifi: fix stop behavior --- nixos/modules/services/networking/unifi.nix | 11 ++++------- nixos/tests/unifi.nix | 11 +++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/networking/unifi.nix b/nixos/modules/services/networking/unifi.nix index 50f8f844188a..1e6236e6d47c 100644 --- a/nixos/modules/services/networking/unifi.nix +++ b/nixos/modules/services/networking/unifi.nix @@ -160,17 +160,14 @@ in serviceConfig = { Type = "notify"; ExecStart = "${cmd} start"; - ExecStop = "${cmd} stop"; + ExecStop = [ + "${cmd} stop" + "${lib.getExe' pkgs.util-linux "waitpid"} -t 30 -e $MAINPID" + ]; Restart = "always"; - TimeoutSec = "5min"; User = "unifi"; UMask = "0077"; WorkingDirectory = "${stateDir}"; - # the stop command exits while the main process is still running, and unifi - # wants to manage its own child processes. this means we have to set KillSignal - # to something the main process ignores, otherwise every stop will have unifi.service - # fail with SIGTERM status. - KillSignal = "SIGCONT"; # Hardening AmbientCapabilities = ""; diff --git a/nixos/tests/unifi.nix b/nixos/tests/unifi.nix index 0f357630b587..a15a622f78b8 100644 --- a/nixos/tests/unifi.nix +++ b/nixos/tests/unifi.nix @@ -21,8 +21,19 @@ machine.wait_for_unit("unifi.service") machine.wait_for_open_port(8880) + machine.succeed("systemctl show unifi.service | grep -q 'ActiveState=active'") + machine.succeed("pgrep mongod") status = json.loads(machine.succeed("curl --silent --show-error --fail-with-body http://localhost:8880/status")) assert status["meta"]["rc"] == "ok" + + machine.succeed("systemctl stop unifi.service") + machine.succeed("systemctl show unifi.service | grep -q 'ActiveState=inactive'") + machine.fail("pgrep mongod") + + machine.succeed("systemctl start unifi.service") + machine.wait_for_unit("unifi.service") + machine.succeed("systemctl show unifi.service | grep -q 'ActiveState=active'") + machine.succeed("pgrep mongod") ''; }