diff --git a/roles/svc-prx-openresty/handlers/main.yml b/roles/svc-prx-openresty/handlers/main.yml index aea48355b0..eabcb2ddf5 100644 --- a/roles/svc-prx-openresty/handlers/main.yml +++ b/roles/svc-prx-openresty/handlers/main.yml @@ -1,4 +1,8 @@ --- - name: Restart and validate OpenResty listen: restart openresty - include_tasks: restart_and_validate.yml + include_tasks: restart.yml + +- name: Reload OpenResty + listen: reload openresty + include_tasks: reload.yml diff --git a/roles/svc-prx-openresty/handlers/reload.yml b/roles/svc-prx-openresty/handlers/reload.yml new file mode 100644 index 0000000000..dfa8b0f70a --- /dev/null +++ b/roles/svc-prx-openresty/handlers/reload.yml @@ -0,0 +1,31 @@ +--- +# A vhost lands in directories.configuration.servers, which sits inside the +# conf.d DIRECTORY bind. A directory keeps its inode across an atomic file +# write, so the running container already sees the new file and SIGHUP is +# enough -- unlike nginx.conf, which is bound as a FILE and whose inode the +# task pins at create time (see restart.yml). +- name: Validate OpenResty configuration before reloading + ansible.builtin.shell: > + container exec {{ lookup('container_address', 'svc-prx-openresty', 'openresty') }} openresty -t -q + register: openresty_test_reload + changed_when: false + retries: 10 + delay: 3 + until: openresty_test_reload.rc == 0 + failed_when: > + openresty_test_reload.rc != 0 and + ('is not running' not in ((openresty_test_reload.stderr | default('')) | lower)) and + ('no such container' not in ((openresty_test_reload.stderr | default('')) | lower)) and + ('is restarting' not in ((openresty_test_reload.stderr | default('')) | lower)) + +- name: Reload OpenResty + ansible.builtin.shell: > + container exec {{ lookup('container_address', 'svc-prx-openresty', 'openresty') }} openresty -s reload + register: openresty_reload + changed_when: openresty_reload.rc == 0 + failed_when: > + openresty_reload.rc != 0 and + ('is not running' not in ((openresty_reload.stderr | default('')) | lower)) and + ('no such container' not in ((openresty_reload.stderr | default('')) | lower)) and + ('is restarting' not in ((openresty_reload.stderr | default('')) | lower)) + when: openresty_test_reload.rc == 0 diff --git a/roles/svc-prx-openresty/handlers/restart_and_validate.yml b/roles/svc-prx-openresty/handlers/restart.yml similarity index 100% rename from roles/svc-prx-openresty/handlers/restart_and_validate.yml rename to roles/svc-prx-openresty/handlers/restart.yml diff --git a/roles/sys-stk-front-proxy/tasks/main.yml b/roles/sys-stk-front-proxy/tasks/main.yml index 0205d4f11c..b3e132187b 100644 --- a/roles/sys-stk-front-proxy/tasks/main.yml +++ b/roles/sys-stk-front-proxy/tasks/main.yml @@ -95,7 +95,7 @@ webserver_websocket_location: "" webserver_client_max_body_size: "{{ lookup('config', front_proxy_application_id, 'server.client_max_body_size', '100m') }}" register: nginx_conf - notify: restart openresty + notify: reload openresty - block: - name: "🔍 Check if {{ lookup('domain', front_proxy_application_id) }} is reachable" @@ -120,3 +120,28 @@ - name: "🔄 Restart Webserver for '{{ front_proxy_domain_conf_dst_resolved }}'" ansible.builtin.meta: flush_handlers + +- name: "🔍 Verify '{{ front_proxy_domain }}' is served after the reload" + uri_probe: + url: "{{ lookup('tls', front_proxy_application_id, 'url.base') }}" + status_code: + - 200 + - 301 + - 302 + register: front_proxy_reload_check + failed_when: false + changed_when: false + when: nginx_conf.changed + +- name: 🔄 Fall back to a full redeploy when the reload did not take + ansible.builtin.command: + cmd: "true" + notify: restart openresty + when: + - nginx_conf.changed + - front_proxy_reload_check.status is defined + - front_proxy_reload_check.status not in [200, 301, 302] + +- name: "🔄 Flush the fallback redeploy for '{{ front_proxy_domain }}'" + ansible.builtin.meta: flush_handlers + when: nginx_conf.changed