nixos/nginx: don't hide nginx config errors on nixos-rebuild --switch with reload enabled (#76179)
nixos/nginx: don't hide nginx config errors on nixos-rebuild --switch with reload enabled Closes https://github.com/NixOS/nixpkgs/issues/73455
This commit is contained in:
parent
4c9e280001
commit
cef68c4580
|
@ -178,6 +178,8 @@ let
|
||||||
then "/etc/nginx/nginx.conf"
|
then "/etc/nginx/nginx.conf"
|
||||||
else configFile;
|
else configFile;
|
||||||
|
|
||||||
|
execCommand = "${cfg.package}/bin/nginx -c '${configPath}' -p '${cfg.stateDir}'";
|
||||||
|
|
||||||
vhosts = concatStringsSep "\n" (mapAttrsToList (vhostName: vhost:
|
vhosts = concatStringsSep "\n" (mapAttrsToList (vhostName: vhost:
|
||||||
let
|
let
|
||||||
onlySSL = vhost.onlySSL || vhost.enableSSL;
|
onlySSL = vhost.onlySSL || vhost.enableSSL;
|
||||||
|
@ -682,10 +684,10 @@ in
|
||||||
stopIfChanged = false;
|
stopIfChanged = false;
|
||||||
preStart = ''
|
preStart = ''
|
||||||
${cfg.preStart}
|
${cfg.preStart}
|
||||||
${cfg.package}/bin/nginx -c '${configPath}' -p '${cfg.stateDir}' -t
|
${execCommand} -t
|
||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${cfg.package}/bin/nginx -c '${configPath}' -p '${cfg.stateDir}'";
|
ExecStart = execCommand;
|
||||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
|
@ -706,11 +708,18 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.nginx-config-reload = mkIf cfg.enableReload {
|
systemd.services.nginx-config-reload = mkIf cfg.enableReload {
|
||||||
wantedBy = [ "nginx.service" ];
|
wants = [ "nginx.service" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
restartTriggers = [ configFile ];
|
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 = ''
|
script = ''
|
||||||
if ${pkgs.systemd}/bin/systemctl -q is-active nginx.service ; then
|
if ${pkgs.systemd}/bin/systemctl -q is-active nginx.service ; then
|
||||||
${pkgs.systemd}/bin/systemctl reload nginx.service
|
${execCommand} -t && \
|
||||||
|
${pkgs.systemd}/bin/systemctl reload nginx.service
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
serviceConfig.RemainAfterExit = true;
|
serviceConfig.RemainAfterExit = true;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import ./make-test-python.nix ({ pkgs, ... }: {
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
||||||
name = "nginx";
|
name = "nginx";
|
||||||
meta = with pkgs.stdenv.lib.maintainers; {
|
meta = with pkgs.stdenv.lib.maintainers; {
|
||||||
maintainers = [ mbbx6spp ];
|
maintainers = [ mbbx6spp danbst ];
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
|
@ -59,6 +59,11 @@ import ./make-test-python.nix ({ pkgs, ... }: {
|
||||||
{
|
{
|
||||||
services.nginx.package = pkgs.nginxUnstable;
|
services.nginx.package = pkgs.nginxUnstable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
services.nginx.package = pkgs.nginxUnstable;
|
||||||
|
services.nginx.virtualHosts."!@$$(#*%".locations."~@#*$*!)".proxyPass = ";;;";
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,6 +73,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
|
||||||
etagSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-1";
|
etagSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-1";
|
||||||
justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-2";
|
justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-2";
|
||||||
reloadRestartSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-3";
|
reloadRestartSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-3";
|
||||||
|
reloadWithErrorsSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-4";
|
||||||
in ''
|
in ''
|
||||||
url = "http://localhost/index.html"
|
url = "http://localhost/index.html"
|
||||||
|
|
||||||
|
@ -110,5 +116,17 @@ import ./make-test-python.nix ({ pkgs, ... }: {
|
||||||
)
|
)
|
||||||
webserver.wait_for_unit("nginx")
|
webserver.wait_for_unit("nginx")
|
||||||
webserver.succeed("journalctl -u nginx | grep -q -i stopped")
|
webserver.succeed("journalctl -u nginx | grep -q -i stopped")
|
||||||
|
|
||||||
|
with subtest("nixos-rebuild --switch should fail when there are configuration errors"):
|
||||||
|
webserver.fail(
|
||||||
|
"${reloadWithErrorsSystem}/bin/switch-to-configuration test >&2"
|
||||||
|
)
|
||||||
|
webserver.succeed("[[ $(systemctl is-failed nginx-config-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"
|
||||||
|
)
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue