diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix index 8d49dc66eb1ab..8b564e451a7c6 100644 --- a/nixos/modules/services/web-servers/nginx/default.nix +++ b/nixos/modules/services/web-servers/nginx/default.nix @@ -698,7 +698,7 @@ in ''; serviceConfig = { ExecStart = execCommand; - ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; + ExecReload = "${execCommand} -s reload"; Restart = "always"; RestartSec = "10s"; StartLimitInterval = "1min"; @@ -721,18 +721,14 @@ in wants = [ "nginx.service" ]; wantedBy = [ "multi-user.target" ]; restartTriggers = [ configFile ]; - # commented, because can cause extra delays during activate for this config: - # services.nginx.virtualHosts."_".locations."/".proxyPass = "http://blabla:3000"; - # stopIfChanged = false; - serviceConfig.Type = "oneshot"; - serviceConfig.TimeoutSec = 60; - script = '' - if ${pkgs.systemd}/bin/systemctl -q is-active nginx.service ; then - ${execCommand} -t && \ - ${pkgs.systemd}/bin/systemctl reload nginx.service - fi - ''; - serviceConfig.RemainAfterExit = true; + serviceConfig = { + Type = "oneshot"; + TimeoutSec = 60; + ExecStart = [ + "/run/current-system/systemd/bin/systemctl reload nginx.service" + ]; + RemainAfterExit = true; + }; }; security.acme.certs = filterAttrs (n: v: v != {}) ( diff --git a/nixos/tests/nginx.nix b/nixos/tests/nginx.nix index 18822f095688b..c3aba9db35fa0 100644 --- a/nixos/tests/nginx.nix +++ b/nixos/tests/nginx.nix @@ -114,16 +114,13 @@ import ./make-test-python.nix ({ pkgs, ... }: { webserver.wait_for_unit("nginx") webserver.succeed("journalctl -u nginx | grep -q -i stopped") - with subtest("nixos-rebuild --switch should fail when there are configuration errors"): - webserver.fail( + with subtest( + "When switching to a broken configuration, the nginx unit should fail to reload" + ): + webserver.succeed( "${reloadWithErrorsSystem}/bin/switch-to-configuration test >&2" ) - webserver.succeed("[[ $(systemctl is-failed nginx-config-reload) == failed ]]") + webserver.succeed("journalctl -u nginx | grep -q -i 'reload failed'") webserver.succeed("[[ $(systemctl is-failed nginx) == active ]]") - # just to make sure operation is idempotent. During development I had a situation - # when first time it shows error, but stops showing it on subsequent rebuilds - webserver.fail( - "${reloadWithErrorsSystem}/bin/switch-to-configuration test >&2" - ) ''; })