Unverified Commit 8bf408f5 authored by Patryk Wychowaniec's avatar Patryk Wychowaniec
Browse files

nixos/unifi: fix stop behavior

parent 83e97f35
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -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 = "";
+11 −0
Original line number Diff line number Diff line
@@ -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")
  '';
}