Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test nginx configuration before reload #207

Merged
merged 1 commit into from
Oct 4, 2023
Merged

Test nginx configuration before reload #207

merged 1 commit into from
Oct 4, 2023

Conversation

stefansundin
Copy link
Contributor

Test the nginx configuration before reloading. This avoids crashing the container if there are configuration errors.

This makes the behavior similar to the nginx systemctl service which tests the nginx configuration before reload to avoid the same issue.

ExecStartPre=/usr/sbin/nginx -t

Fixes #206.

Log output on valid configuration:

examples-nginx-certbot-1  | 2023/09/22 21:28:36 [info] Received SIGHUP signal; terminating the autorenewal sleep process
examples-nginx-certbot-1  | Terminated
examples-nginx-certbot-1  | 2023/09/22 21:28:36 [info] Running the autorenewal service
examples-nginx-certbot-1  | 2023/09/22 21:28:36 [info] Starting certificate renewal process
examples-nginx-certbot-1  | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
examples-nginx-certbot-1  | nginx: configuration file /etc/nginx/nginx.conf test is successful
examples-nginx-certbot-1  | 2023/09/22 21:28:36 [notice] 407#407: signal process started
examples-nginx-certbot-1  | 2023/09/22 21:28:36 [notice] 68#68: signal 1 (SIGHUP) received from 407, reconfiguring
examples-nginx-certbot-1  | 2023/09/22 21:28:36 [notice] 68#68: reconfiguring
examples-nginx-certbot-1  | 2023/09/22 21:28:36 [info] Autorenewal service will now sleep 8d

Log output on invalid configuration:

examples-nginx-certbot-1  | 2023/09/22 21:29:09 [info] Received SIGHUP signal; terminating the autorenewal sleep process
examples-nginx-certbot-1  | Terminated
examples-nginx-certbot-1  | 2023/09/22 21:29:09 [info] Running the autorenewal service
examples-nginx-certbot-1  | 2023/09/22 21:29:09 [info] Starting certificate renewal process
examples-nginx-certbot-1  | 2023/09/22 21:29:09 [emerg] 321#321: unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/example_server.conf:10
examples-nginx-certbot-1  | nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/example_server.conf:10
examples-nginx-certbot-1  | nginx: configuration file /etc/nginx/nginx.conf test failed
examples-nginx-certbot-1  | 
examples-nginx-certbot-1  | 
examples-nginx-certbot-1  | 2023/09/22 21:29:09 [error] Nginx configuration is invalid, skipped reloading. Check the logs for details.
examples-nginx-certbot-1  | 
examples-nginx-certbot-1  | 2023/09/22 21:29:09 [info] Autorenewal service will now sleep 8d

…he container if there are configuration errors.
@JonasAlfredsson
Copy link
Owner

Sorry for the delay, a real bad cold had me offline for almost a week.
I think you have made enough valid points to have this merged, however, I will still make this a major release since I do believe it alters the behavior enough that users should be aware of it.

@JonasAlfredsson JonasAlfredsson merged commit 6e0b8bd into JonasAlfredsson:master Oct 4, 2023
1 check passed
@JonasAlfredsson JonasAlfredsson added the hacktoberfest-accepted Used to accept pull request during Hacktoberfest. label Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Used to accept pull request during Hacktoberfest.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test nginx config on SIGHUP
2 participants