More elegant approach for nginx reloads#542
Merged
Merged
Conversation
- Use `systemctl try-reload-or-restart` to only trigger a reload of the `nginx` service if it's already running (so only on the active cluster node): <https://man7.org/linux/man-pages/man1/systemctl.1.html> ```text try-reload-or-restart PATTERN... Reload one or more units if they support it. If not, stop and then start them instead. This does nothing if the units are not running. ``` - Drop explicit configuration validation (`nginx -t`), which is already done implicitly when running `nginx -s reload` (which is what the `ExecReload` property of the nginx systemd unit service file does): ```bash $ systemctl show nginx.service --property=ExecReload ExecReload={ path=/usr/bin/nginx ; argv[]=/usr/bin/nginx -s reload ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 } ``` <https://nginx.org/en/docs/beginners_guide.html#control> ```text Changes made in the configuration file will not be applied until the command to reload configuration is sent to nginx or it is restarted. To reload configuration, execute: nginx -s reload Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process starts new worker processes and sends messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop accepting new connections and continue to service current requests until all such requests are serviced. After that, the old worker processes exit. ``` - Only run on relevant hosts ("web" ones). - Drop unnecessary stderr output (with this new approach)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
systemctl try-reload-or-restartto only trigger a reload of thenginxservice if it's already running (so only on the active cluster node):https://man7.org/linux/man-pages/man1/systemctl.1.html
nginx -t), which is already done implicitly when runningnginx -s reload(which is what theExecReloadproperty of the nginx systemd unit service file does):$ systemctl show nginx.service --property=ExecReload ExecReload={ path=/usr/bin/nginx ; argv[]=/usr/bin/nginx -s reload ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }https://nginx.org/en/docs/beginners_guide.html#control
Only run on relevant hosts ("web" ones).
Drop unnecessary stderr output (with this new approach)