Skip to content

nginx: Check config syntax validity with nginx -t in preStart - #24664

Merged
joachifm merged 1 commit into
NixOS:masterfrom
nh2:nginx-check-config
Feb 17, 2018
Merged

joachifm merged 1 commit into
NixOS:masterfrom
nh2:nginx-check-config

Conversation

@nh2

@nh2 nh2 commented Apr 6, 2017

Copy link
Copy Markdown
Contributor
Motivation for this change

Currently nginx in NixOS doesn't use the standard practice of checking its config file in systemd's ExecPreStart (this is what ExecPreStart was made for).

This results in nixops deployments to succeed even with wrong config file syntax.

By checking the config file syntax in preStart using nginx -t, a nixops will fail correctly on wrong config file syntax.

@mention-bot

Copy link
Copy Markdown

@nh2, thanks for your PR! By analyzing the history of the files in this pull request, we identified @globin, @domenkozar and @fadenb to be potential reviewers.

@nh2
nh2 force-pushed the nginx-check-config branch from 2155b55 to f68c9fb Compare April 6, 2017 02:56
@Mic92

Mic92 commented Apr 6, 2017

Copy link
Copy Markdown
Member

In ferm, I check that the configuration is valid, even before the update is applied to the system.
However I fear this will not work here, because nginx would try to resolve ips during configuration check:
https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/networking/ferm.nix#L14

@domenkozar

Copy link
Copy Markdown
Member

There have been many attempts at getting this right (see closed PRs), you can find the latest at #24476

@domenkozar domenkozar closed this Apr 6, 2017
@nh2

nh2 commented Apr 6, 2017

Copy link
Copy Markdown
Contributor Author

There have been many attempts at getting this right (see closed PRs), you can find the latest at #24476

@domenkozar I am confused, this issue is not about reloading without restarting. This issue is about making sure that starting with invalid config file fails before systemd counts the service as running.

@nh2

nh2 commented Sep 27, 2017

Copy link
Copy Markdown
Contributor Author

@domenkozar Ping, as I cannot reopen this myself apparently.

@domenkozar domenkozar reopened this Sep 27, 2017
@Mic92
Mic92 requested a review from fpletz September 27, 2017 20:47
@joachifm

Copy link
Copy Markdown
Contributor

@GrahamcOfBorg test nginx

@GrahamcOfBorg

Copy link
Copy Markdown

Success on x86_64-linux (full log)

Partial log (click to expand)

webserver: exit status 1
syncing
webserver: running command: sync
webserver: exit status 0
test script finished in 9.83s
cleaning up
killing webserver (pid 593)
vde_switch: EOF on stdin, cleaning up and exiting
vde_switch: Could not remove ctl dir '/tmp/nix-build-vm-test-run-nginx.drv-0/vde1.ctl': Directory not empty
/nix/store/n06m7s6lgdx0hq23nc20mm49fp6hw9y9-vm-test-run-nginx

@GrahamcOfBorg

Copy link
Copy Markdown

Success on aarch64-linux (full log)

Partial log (click to expand)

webserver: exit status 1
syncing
webserver: running command: sync
webserver: exit status 0
test script finished in 17.88s
cleaning up
killing webserver (pid 627)
vde_switch: EOF on stdin, cleaning up and exiting
vde_switch: Could not remove ctl dir '/build/vde1.ctl': Directory not empty
/nix/store/fr2l4vynh8gm24a850l3iwfnf5hcfnbk-vm-test-run-nginx

@joachifm
joachifm merged commit f00a151 into NixOS:master Feb 17, 2018
@nh2

nh2 commented Feb 23, 2018

Copy link
Copy Markdown
Contributor Author

@volth Agreed -- I think both are useful. The preStart check so that you see if something is wrong if you systemctl start something manually, or somehow configured nginx to load a config file not controlled by nix, and also so that commands like nixops deploy fail loudly (because it doesn't return before preStart is over).

I think we should open another issue to add nix-evaluation-time config checking for nginx, like you did for Varnish.

@nh2

nh2 commented Feb 23, 2018

Copy link
Copy Markdown
Contributor Author

I think we should open another issue to add nix-evaluation-time config checking for nginx

Done in #35395

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants