nixos/unifi: fix stop behavior

This commit is contained in:
Patryk Wychowaniec 2026-04-01 21:38:57 +02:00
commit 8bf408f553
No known key found for this signature in database
GPG key ID: F62547D075E09767
2 changed files with 15 additions and 7 deletions

View file

@ -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 = "";

View file

@ -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")
'';
}