diff --git a/plugins/lookup/container_healthcheck.py b/plugins/lookup/container_healthcheck.py new file mode 100644 index 0000000000..38a947232c --- /dev/null +++ b/plugins/lookup/container_healthcheck.py @@ -0,0 +1,128 @@ +"""Lookup `container_healthcheck`: emit a service's healthcheck block. + +Single SPOT for every container probe in the repo. The service name is the +only positional argument, everything else comes from the service's +``meta/services.yml`` entry: + + myservice: + ports: + internal: + http: 8080 + healthcheck: + flavor: curl + path: health/ready + start_period: 20m + +``flavor`` picks the probe shape (see utils/docker/healthcheck.py); each +flavor brings its own interval, timeout, retries and start_period, and any +of those may be overridden next to it. Without a ``flavor`` the entry must +carry an explicit ``test`` argv. ``port_key`` selects another entry below +``ports.internal`` for services that expose their probe on a second port. + +Examples: + + {{ lookup('container_healthcheck', service_name) | indent(4) }} + {{ lookup('container_healthcheck', service_name, samples=3) | indent(4) }} +""" + +from __future__ import annotations + +from typing import Any + +from ansible.errors import AnsibleError +from ansible.plugins.loader import lookup_loader +from ansible.plugins.lookup import LookupBase + +from utils.docker.healthcheck import PROBES, build, known_flavors + + +class LookupModule(LookupBase): + def run( + self, + terms: list[Any] | None, + variables: dict[str, Any] | None = None, + **kwargs: Any, + ) -> list[str]: + if not terms or not str(terms[0] or "").strip(): + raise AnsibleError( + "container_healthcheck: pass the service name as the first argument, " + "e.g. lookup('container_healthcheck', service_name)" + ) + service = str(terms[0]).strip() + + self._vars = ( + variables or getattr(self._templar, "available_variables", {}) or {} + ) + self._application_id = kwargs.get("application_id") or self._vars.get( + "application_id" + ) + if not self._application_id: + raise AnsibleError( + "container_healthcheck: no application_id in the play vars; " + "pass application_id= explicitly" + ) + + config = self._config(f"services.{service}.healthcheck", {}) + config = config if isinstance(config, dict) else {} + flavor = str(config.get("flavor", "") or "").strip() + where = f"'{self._application_id}' service '{service}'" + + if not flavor and not config.get("test"): + raise AnsibleError( + f"container_healthcheck: {where} declares no healthcheck.flavor, so " + f"healthcheck.test is required. Known flavors: {known_flavors()}." + ) + if flavor and flavor not in PROBES: + raise AnsibleError( + f"container_healthcheck: unknown flavor '{flavor}' for {where}. " + f"Known flavors: {known_flavors()}." + ) + + return [build(flavor, config, **self._context(service, flavor, config, kwargs))] + + def _context( + self, + service: str, + flavor: str, + config: dict[str, Any], + kwargs: dict[str, Any], + ) -> dict[str, Any]: + """Collect what the chosen flavor's probe asks for. + + Args: + service: service key inside the application's services.yml. + flavor: the selected probe shape, empty for an explicit test. + config: that service's healthcheck entry. + kwargs: the call site's keyword arguments. + """ + hostname = config.get("hostname", self._vars.get("container_hostname")) + port_key = str(config.get("port_key", "http") or "http") + context = { + "test": config.get("test"), + "port": self._config(f"services.{service}.ports.internal.{port_key}", "") + or "", + "path": str(config.get("path", "") or ""), + "hostname": str(hostname) if hostname else None, + "samples": int(kwargs.get("samples", config.get("samples", 1)) or 1), + } + if flavor == "msmtp_curl": + context.update( + email_enabled=bool(self._config("services.email.enabled", False)), + domain=self._lookup("domain", self._application_id), + blackhole=(self._lookup("users", "blackhole") or {}).get("email", ""), + ) + return context + + def _config(self, path: str, default: Any) -> Any: + """Read one services.yml value through the config SPOT, templated. + + Args: + path: dotted config path below the application. + default: value returned when the path is absent. + """ + return self._lookup("config", self._application_id, path, default) + + def _lookup(self, name: str, *terms: Any) -> Any: + return lookup_loader.get( + name, loader=self._loader, templar=getattr(self, "_templar", None) + ).run(list(terms), variables=self._vars)[0] diff --git a/roles/sys-svc-container/templates/healthcheck/curl.yml.j2 b/roles/sys-svc-container/templates/healthcheck/curl.yml.j2 deleted file mode 100644 index e7a069df6a..0000000000 --- a/roles/sys-svc-container/templates/healthcheck/curl.yml.j2 +++ /dev/null @@ -1,16 +0,0 @@ -{% set container_port = container_port | default(lookup('config', application_id, 'services.' ~ service_name ~ '.ports.internal.http', '')) %} - healthcheck: - test: - - "CMD" - - "curl" - - "-f" -{% if container_hostname is defined %} - - "-H" - - "Host: {{ container_hostname }}" -{% endif %} - - "http://127.0.0.1{{ (":" ~ container_port) if container_port else '' }}/{{ container_healthcheck | default('') }}" - interval: 1m - timeout: 10s - retries: 3 - start_period: {{ container_healthcheck_start_period | default('30s') }} -{{ "\n" }} diff --git a/roles/sys-svc-container/templates/healthcheck/http.yml.j2 b/roles/sys-svc-container/templates/healthcheck/http.yml.j2 deleted file mode 100644 index 4892653991..0000000000 --- a/roles/sys-svc-container/templates/healthcheck/http.yml.j2 +++ /dev/null @@ -1,7 +0,0 @@ -{% set container_port = container_port | default(lookup('config', application_id, 'services.' ~ service_name ~ '.ports.internal.http', '')) %} - healthcheck: - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:{{ container_port }}/ >/dev/null || curl -fsS http://127.0.0.1:{{ container_port }}/ >/dev/null"] - interval: 30s - timeout: 5s - retries: 5 - start_period: {{ container_healthcheck_start_period | default('20s') }} diff --git a/roles/sys-svc-container/templates/healthcheck/http_status.yml.j2 b/roles/sys-svc-container/templates/healthcheck/http_status.yml.j2 deleted file mode 100644 index 2fb32c71b9..0000000000 --- a/roles/sys-svc-container/templates/healthcheck/http_status.yml.j2 +++ /dev/null @@ -1,12 +0,0 @@ -{% set container_port = container_port | default(lookup('config', application_id, 'services.' ~ service_name ~ '.ports.internal.http', '')) %} - healthcheck: - test: - - "CMD" - - "bash" - - "-c" - - "exec 3<>/dev/tcp/localhost/{{ container_port }} && echo -e 'GET /{{ container_healthcheck }} HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n' >&3 && head -n1 <&3 | grep -qE '^HTTP/1\\.[01] [23][0-9][0-9]'" - interval: 30s - timeout: 5s - retries: 3 - start_period: {{ container_healthcheck_start_period | default('30s') }} -{{ "\n" }} diff --git a/roles/sys-svc-container/templates/healthcheck/msmtp_curl.yml.j2 b/roles/sys-svc-container/templates/healthcheck/msmtp_curl.yml.j2 deleted file mode 100644 index 37b63b281d..0000000000 --- a/roles/sys-svc-container/templates/healthcheck/msmtp_curl.yml.j2 +++ /dev/null @@ -1,28 +0,0 @@ -{# - This health check ensures the test email is sent only once to prevent - hitting SMTP rate limits due to multiple health check executions. - The logic checks for a temporary file (/tmp/email_sent) to determine - if the email has already been sent. If the file exists, the email - is skipped, but the health check continues by verifying the HTTP service. - Additional it is also checked if the host is reachable. - - When the role's `services.email.enabled` flag resolves to false (the - operator opted out of the email provider, or the SMTP host is missing - for any other reason), the msmtp branch is suppressed entirely so the - container does not flap into `unhealthy` because of an unrelated SMTP - outage. The HTTP probe stays the canonical liveness signal. #} - healthcheck: - test: - - CMD-SHELL - - > - {%+ if (lookup('config', application_id, 'services.email.enabled', false) | bool) -%} - if [ ! -f /tmp/email_sent ]; then - echo 'Subject: testmessage from {{ lookup("domain",application_id) }}\n\nSUCCESSFULL' | msmtp -t {{ lookup('users', 'blackhole').email }} && touch /tmp/email_sent; - fi && - {%+ endif -%} - curl -f http://localhost:80/ || exit 1 - interval: 30s - timeout: 20s - retries: 5 - start_period: 120s -{{ "\n" }} diff --git a/roles/sys-svc-container/templates/healthcheck/nc.yml.j2 b/roles/sys-svc-container/templates/healthcheck/nc.yml.j2 deleted file mode 100644 index 19c77a4f74..0000000000 --- a/roles/sys-svc-container/templates/healthcheck/nc.yml.j2 +++ /dev/null @@ -1,8 +0,0 @@ -{% set container_port = container_port | default(lookup('config', application_id, 'services.' ~ service_name ~ '.ports.internal.http', '')) %} - healthcheck: - test: ["CMD-SHELL", "nc -z localhost {{ container_port }} || exit 1"] - interval: 30s - timeout: 3s - retries: 3 - start_period: {{ container_healthcheck_start_period | default('10s') }} -{{ "\n" }} diff --git a/roles/sys-svc-container/templates/healthcheck/tcp.yml.j2 b/roles/sys-svc-container/templates/healthcheck/tcp.yml.j2 deleted file mode 100644 index eafd04752f..0000000000 --- a/roles/sys-svc-container/templates/healthcheck/tcp.yml.j2 +++ /dev/null @@ -1,12 +0,0 @@ -{% set container_port = container_port | default(lookup('config', application_id, 'services.' ~ service_name ~ '.ports.internal.http', '')) %} - healthcheck: - test: - - "CMD" - - "bash" - - "-c" - - "exec 3<>/dev/tcp/localhost/{{ container_port }} && echo -e 'GET /{{ container_healthcheck | default('') }} HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n' >&3 && cat <&3 | grep -q 'HTTP/1'" - interval: 30s - timeout: 5s - retries: 3 - start_period: {{ container_healthcheck_start_period | default('30s') }} -{{ "\n" }} diff --git a/roles/sys-svc-container/templates/healthcheck/wget.yml.j2 b/roles/sys-svc-container/templates/healthcheck/wget.yml.j2 deleted file mode 100644 index e8112895d3..0000000000 --- a/roles/sys-svc-container/templates/healthcheck/wget.yml.j2 +++ /dev/null @@ -1,13 +0,0 @@ -{% set container_port = container_port | default(lookup('config', application_id, 'services.' ~ service_name ~ '.ports.internal.http', '')) %} - healthcheck: - test: - - "CMD" - - "wget" - - "--spider" - - "--proxy=off" - - "http://127.0.0.1{{ (":" ~ container_port) if container_port else '' }}/{{ container_healthcheck | default('') }}" - interval: 1m - timeout: 10s - retries: 3 - start_period: {{ container_healthcheck_start_period | default('30s') }} -{{ "\n" }} diff --git a/roles/web-app-akaunting/meta/services.yml b/roles/web-app-akaunting/meta/services.yml index 0f4aaf30eb..f6983786c3 100644 --- a/roles/web-app-akaunting/meta/services.yml +++ b/roles/web-app-akaunting/meta/services.yml @@ -36,6 +36,9 @@ ldap: enabled: false shared: false akaunting: + healthcheck: + flavor: tcp + start_period: 10m modes: compose: enabled: true diff --git a/roles/web-app-akaunting/templates/compose.yml.j2 b/roles/web-app-akaunting/templates/compose.yml.j2 index ddc8cacad3..d54a39d615 100644 --- a/roles/web-app-akaunting/templates/compose.yml.j2 +++ b/roles/web-app-akaunting/templates/compose.yml.j2 @@ -1,5 +1,4 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {% set container_healthcheck_start_period = '10m' %} {% set service_name = 'akaunting' %} {{ service_name }}: @@ -12,7 +11,7 @@ {{ lookup('compose_only', 'pull_policy', 'never') }} {{ lookup('container_ports', ['akaunting', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'akaunting') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} diff --git a/roles/web-app-bluesky/meta/services.yml b/roles/web-app-bluesky/meta/services.yml index 5252ea8198..04afa5ba76 100644 --- a/roles/web-app-bluesky/meta/services.yml +++ b/roles/web-app-bluesky/meta/services.yml @@ -44,6 +44,8 @@ sso: # nocheck: playwright-service-flag - internal sub-component (multi-entity role) web: enabled: true + healthcheck: + flavor: tcp ports: local: http: 8031 @@ -109,6 +111,9 @@ prometheus: enabled: "{{ 'web-app-prometheus' in group_names }}" shared: "{{ 'web-app-prometheus' in group_names }}" api: + healthcheck: + flavor: wget + path: xrpc/_health ports: local: http: 8030 diff --git a/roles/web-app-bluesky/templates/compose.yml.j2 b/roles/web-app-bluesky/templates/compose.yml.j2 index 74883a2b56..ebbbae87f2 100644 --- a/roles/web-app-bluesky/templates/compose.yml.j2 +++ b/roles/web-app-bluesky/templates/compose.yml.j2 @@ -1,8 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {# nocheck: container-port-set-unused #} - {% set container_port = BLUESKY_PDS_INTERNAL_PORT | int %} - {% set container_healthcheck = 'xrpc/_health' %} {% set service_name = 'pds' %} {{ service_name }}: {{ lookup('container_image', application_id, 'pds') }} @@ -10,13 +7,11 @@ {{ lookup('container_volumes', application_id, 'pds') | indent(4) }} {{ lookup('container_ports', ['api', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} + {{ lookup('container_healthcheck', 'api') | indent(4) }} {{ lookup('container_networks') | indent(4) }} {% if BLUESKY_WEB_ENABLED %} {% set service_name = 'web' %} - {# nocheck: container-port-set-unused #} - {% set container_port = BLUESKY_WEB_INTERNAL_PORT | int %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/deploy.yml.j2' %} command: ["bskyweb","serve"] @@ -26,7 +21,7 @@ {{ lookup('container_image', application_id, 'web', image=BLUESKY_WEB_IMAGE_CUSTOM) }} {{ lookup('compose_only', 'pull_policy', 'never') }} {{ lookup('container_ports', ['web', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {% set service_name = BLUESKY_BROKER_SERVICE %} diff --git a/roles/web-app-bookwyrm/meta/services.yml b/roles/web-app-bookwyrm/meta/services.yml index 164da36762..4adab888a5 100644 --- a/roles/web-app-bookwyrm/meta/services.yml +++ b/roles/web-app-bookwyrm/meta/services.yml @@ -47,6 +47,8 @@ redis: mem_limit: 512m pids_limit: 512 bookwyrm: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-bookwyrm/templates/compose.yml.j2 b/roles/web-app-bookwyrm/templates/compose.yml.j2 index c00a8952d8..126fb6b8e4 100644 --- a/roles/web-app-bookwyrm/templates/compose.yml.j2 +++ b/roles/web-app-bookwyrm/templates/compose.yml.j2 @@ -22,7 +22,7 @@ hostname: "{{ BOOKWYRM_HOSTNAME }}" {{ lookup('container_ports', ['bookwyrm', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'bookwyrm') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-bridgy-fed/meta/services.yml b/roles/web-app-bridgy-fed/meta/services.yml index 2d84afa24b..93437a5f78 100644 --- a/roles/web-app-bridgy-fed/meta/services.yml +++ b/roles/web-app-bridgy-fed/meta/services.yml @@ -39,6 +39,8 @@ prometheus: enabled: "{{ 'web-app-prometheus' in group_names }}" shared: "{{ 'web-app-prometheus' in group_names }}" bridgy-fed: + healthcheck: + flavor: tcp modes: compose: enabled: true diff --git a/roles/web-app-bridgy-fed/templates/compose.yml.j2 b/roles/web-app-bridgy-fed/templates/compose.yml.j2 index 3469d9b190..faee6a7f49 100644 --- a/roles/web-app-bridgy-fed/templates/compose.yml.j2 +++ b/roles/web-app-bridgy-fed/templates/compose.yml.j2 @@ -10,7 +10,7 @@ {{ lookup('compose_only', 'container_name', BRIDGY_CONTAINER) }} hostname: "{{ container_hostname }}" {{ lookup('container_ports', ['bridgy-fed', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-checkmk/meta/services.yml b/roles/web-app-checkmk/meta/services.yml index c921826624..46817c4022 100644 --- a/roles/web-app-checkmk/meta/services.yml +++ b/roles/web-app-checkmk/meta/services.yml @@ -48,6 +48,9 @@ prometheus: enabled: "{{ 'web-app-prometheus' in group_names }}" shared: "{{ 'web-app-prometheus' in group_names }}" checkmk: + healthcheck: + flavor: curl + path: cmk/check_mk/login.py modes: compose: enabled: true diff --git a/roles/web-app-checkmk/templates/compose.yml.j2 b/roles/web-app-checkmk/templates/compose.yml.j2 index ea8303b86f..f3c7820199 100644 --- a/roles/web-app-checkmk/templates/compose.yml.j2 +++ b/roles/web-app-checkmk/templates/compose.yml.j2 @@ -1,12 +1,11 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'checkmk' %} - {% set container_healthcheck = 'cmk/check_mk/login.py' %} {{ service_name }}: {{ lookup('container_image', application_id, 'checkmk') }} {{ lookup('compose_only', 'container_name', CHECKMK_NAME) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_ports', ['checkmk', 'http', DOCKER_BIND_HOST], ['checkmk', 'agent', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} diff --git a/roles/web-app-chess/meta/services.yml b/roles/web-app-chess/meta/services.yml index 3ef174b35e..cd5267dc1e 100644 --- a/roles/web-app-chess/meta/services.yml +++ b/roles/web-app-chess/meta/services.yml @@ -23,6 +23,8 @@ postgres: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-postgres' in group_names }}" chess: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-chess/templates/compose.yml.j2 b/roles/web-app-chess/templates/compose.yml.j2 index bb07397a9d..4eeec4e634 100644 --- a/roles/web-app-chess/templates/compose.yml.j2 +++ b/roles/web-app-chess/templates/compose.yml.j2 @@ -6,7 +6,7 @@ hostname: "{{ CHESS_HOSTNAME }}" {{ lookup('container_ports', ['chess', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, CHESS_SERVICE) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-confluence/meta/services.yml b/roles/web-app-confluence/meta/services.yml index dd154315b5..1dbdbff4be 100644 --- a/roles/web-app-confluence/meta/services.yml +++ b/roles/web-app-confluence/meta/services.yml @@ -28,6 +28,8 @@ postgres: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-postgres' in group_names }}" confluence: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-confluence/templates/compose.yml.j2 b/roles/web-app-confluence/templates/compose.yml.j2 index 370c216170..f62ed34219 100644 --- a/roles/web-app-confluence/templates/compose.yml.j2 +++ b/roles/web-app-confluence/templates/compose.yml.j2 @@ -11,7 +11,7 @@ hostname: '{{ CONFLUENCE_HOSTNAME}}' {{ lookup('container_ports', ['confluence', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'confluence') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-dashboard/meta/services.yml b/roles/web-app-dashboard/meta/services.yml index 39a6907db2..1f4257a69d 100644 --- a/roles/web-app-dashboard/meta/services.yml +++ b/roles/web-app-dashboard/meta/services.yml @@ -27,6 +27,9 @@ matomo: shared: "{{ 'web-app-matomo' in group_names }}" # nocheck: playwright-service-flag — self-provider dashboard: + healthcheck: + flavor: tcp + start_period: 10m modes: compose: enabled: true diff --git a/roles/web-app-dashboard/templates/compose.yml.j2 b/roles/web-app-dashboard/templates/compose.yml.j2 index d39bb99d34..7e11c07f4a 100644 --- a/roles/web-app-dashboard/templates/compose.yml.j2 +++ b/roles/web-app-dashboard/templates/compose.yml.j2 @@ -1,6 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'dashboard' %} - {% set container_healthcheck_start_period = '10m' %} {% set container_port = lookup('config', application_id, 'services.' ~ service_name ~ '.ports.internal.http') %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/deploy.yml.j2' %} @@ -11,7 +10,7 @@ {{ lookup('container_volumes', application_id, service_name) | indent(4) }} {{ lookup('compose_restart') }} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-decidim/meta/services.yml b/roles/web-app-decidim/meta/services.yml index f6324c8743..c6281ed463 100644 --- a/roles/web-app-decidim/meta/services.yml +++ b/roles/web-app-decidim/meta/services.yml @@ -27,6 +27,9 @@ postgres: shared: "{{ 'svc-db-postgres' in group_names }}" enabled: true # nocheck: dynamic-flag decidim: + healthcheck: + flavor: curl + path: health_check modes: compose: enabled: true diff --git a/roles/web-app-decidim/templates/compose.yml.j2 b/roles/web-app-decidim/templates/compose.yml.j2 index 91e874fae2..c86ba1c3d5 100644 --- a/roles/web-app-decidim/templates/compose.yml.j2 +++ b/roles/web-app-decidim/templates/compose.yml.j2 @@ -1,7 +1,6 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'decidim' %} - {% set container_healthcheck = 'health_check' %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} @@ -23,7 +22,7 @@ - "{{ lookup('config', 'web-app-seaweedfs', 'domains.canonical.api') }}:host-gateway" {% endif %} {{ lookup('container_depends_on', application_id) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} {{ lookup('compose_networks') }} diff --git a/roles/web-app-erpnext/meta/services.yml b/roles/web-app-erpnext/meta/services.yml index d1a9dc641f..b3182661cc 100644 --- a/roles/web-app-erpnext/meta/services.yml +++ b/roles/web-app-erpnext/meta/services.yml @@ -81,6 +81,9 @@ erpnext: pids_limit: 2048 backend: name: erpnext-backend + healthcheck: + flavor: tcp + start_period: 10m ports: internal: http: 8000 diff --git a/roles/web-app-erpnext/templates/compose.yml.j2 b/roles/web-app-erpnext/templates/compose.yml.j2 index 7b83221cce..86417da731 100644 --- a/roles/web-app-erpnext/templates/compose.yml.j2 +++ b/roles/web-app-erpnext/templates/compose.yml.j2 @@ -8,6 +8,7 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} entrypoint: ["bash", "-c", "{{ ERPNEXT_CONFIG_READY_GATE }} exec /usr/local/bin/entrypoint.sh /home/frappe/frappe-bench/env/bin/gunicorn --chdir=/home/frappe/frappe-bench/sites --bind=0.0.0.0:{{ ERPNEXT_BACKEND_PORT }} --threads=4 --workers=2 --worker-class=gthread --worker-tmp-dir=/dev/shm --timeout=120 --preload frappe.app:application"] {{ lookup('depends_on', {'configurator': 'service_completed_successfully'}) }} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_volumes', application_id, ERPNEXT_BACKEND_CONTAINER) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-espocrm/meta/services.yml b/roles/web-app-espocrm/meta/services.yml index de55ff798d..f0576db19b 100644 --- a/roles/web-app-espocrm/meta/services.yml +++ b/roles/web-app-espocrm/meta/services.yml @@ -54,6 +54,9 @@ espocrm: local: websocket: 4002 http: 8040 + healthcheck: + flavor: curl + start_period: 15m run_after: - web-app-keycloak - web-app-mailu diff --git a/roles/web-app-espocrm/templates/compose.yml.j2 b/roles/web-app-espocrm/templates/compose.yml.j2 index 9b904a2dc6..63439645d7 100644 --- a/roles/web-app-espocrm/templates/compose.yml.j2 +++ b/roles/web-app-espocrm/templates/compose.yml.j2 @@ -1,7 +1,6 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = ESPOCRM_SERVICE %} - {% set container_healthcheck_start_period = '15m' %} {{ service_name }}: {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} args: @@ -17,7 +16,7 @@ stop_signal: SIGTERM stop_grace_period: 30s {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_ports', ['espocrm', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-fediwall/meta/services.yml b/roles/web-app-fediwall/meta/services.yml index b56f6bb266..6837137c98 100644 --- a/roles/web-app-fediwall/meta/services.yml +++ b/roles/web-app-fediwall/meta/services.yml @@ -44,6 +44,8 @@ friendica: enabled: "{{ 'web-app-friendica' in group_names }}" shared: "{{ 'web-app-friendica' in group_names }}" fediwall: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-fediwall/templates/compose.yml.j2 b/roles/web-app-fediwall/templates/compose.yml.j2 index bd503d8b2a..e9b6a3eda7 100644 --- a/roles/web-app-fediwall/templates/compose.yml.j2 +++ b/roles/web-app-fediwall/templates/compose.yml.j2 @@ -9,7 +9,7 @@ FEDIWALL_DIST_DIR_REL: "{{ FEDIWALL_DIST_DIR_REL }}" {{ lookup('container_image', application_id, 'fediwall') }} {{ lookup('container_ports', ['fediwall', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-friendica/meta/services.yml b/roles/web-app-friendica/meta/services.yml index 2fd2ddd7c5..52d7ff0e7d 100644 --- a/roles/web-app-friendica/meta/services.yml +++ b/roles/web-app-friendica/meta/services.yml @@ -2,6 +2,8 @@ # nocheck: seaweedfs-required, object storage not implemented for this role # nocheck: playwright-service-flag, self-provider friendica: + healthcheck: + flavor: msmtp_curl modes: compose: enabled: true diff --git a/roles/web-app-friendica/templates/compose.yml.j2 b/roles/web-app-friendica/templates/compose.yml.j2 index 823b3c28af..7b7707fcf3 100644 --- a/roles/web-app-friendica/templates/compose.yml.j2 +++ b/roles/web-app-friendica/templates/compose.yml.j2 @@ -16,7 +16,7 @@ {{ lookup('container_volumes', application_id, FRIENDICA_SERVICE) | indent(4) }} {{ lookup('container_ports', ['friendica', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/msmtp_curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} diff --git a/roles/web-app-fusiondirectory/meta/services.yml b/roles/web-app-fusiondirectory/meta/services.yml index b3f8de80ad..92967bd8c4 100644 --- a/roles/web-app-fusiondirectory/meta/services.yml +++ b/roles/web-app-fusiondirectory/meta/services.yml @@ -35,6 +35,8 @@ sso: allowed_groups: - "{{ lookup('rbac_group_path', application_id='web-app-fusiondirectory', role='administrator') }}" fusiondirectory: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-fusiondirectory/templates/compose.yml.j2 b/roles/web-app-fusiondirectory/templates/compose.yml.j2 index adbaf7c9dc..586b4b3d09 100644 --- a/roles/web-app-fusiondirectory/templates/compose.yml.j2 +++ b/roles/web-app-fusiondirectory/templates/compose.yml.j2 @@ -6,7 +6,7 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_ports', ['fusiondirectory', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'fusiondirectory') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-gitea/meta/services.yml b/roles/web-app-gitea/meta/services.yml index 30c0c07a91..524c92275a 100644 --- a/roles/web-app-gitea/meta/services.yml +++ b/roles/web-app-gitea/meta/services.yml @@ -59,6 +59,8 @@ gitea: mem_reservation: 1g mem_limit: 2g pids_limit: 1024 + healthcheck: + flavor: curl title: "{{ SOFTWARE_NAME }} Code Hub" configuration: repository: diff --git a/roles/web-app-gitea/templates/compose.yml.j2 b/roles/web-app-gitea/templates/compose.yml.j2 index 8ad55e14bc..75f9a6415b 100644 --- a/roles/web-app-gitea/templates/compose.yml.j2 +++ b/roles/web-app-gitea/templates/compose.yml.j2 @@ -9,7 +9,7 @@ ['gitea', 'http', DOCKER_BIND_HOST], ['gitea', 'ssh']) | indent(4) }} {{ lookup('container_volumes', application_id, 'gitea') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} diff --git a/roles/web-app-gitlab/meta/services.yml b/roles/web-app-gitlab/meta/services.yml index 1967effd66..bc66d07437 100644 --- a/roles/web-app-gitlab/meta/services.yml +++ b/roles/web-app-gitlab/meta/services.yml @@ -79,6 +79,10 @@ webservice: mem_limit: 6g pids_limit: 2048 sidekiq: + healthcheck: + flavor: tcp + path: liveness + start_period: 300s image: registry.gitlab.com/gitlab-org/build/cng/gitlab-sidekiq-ce version: v19.1.2 name: gitlab-sidekiq diff --git a/roles/web-app-gitlab/templates/compose.yml.j2 b/roles/web-app-gitlab/templates/compose.yml.j2 index d82799c570..2e82825ede 100644 --- a/roles/web-app-gitlab/templates/compose.yml.j2 +++ b/roles/web-app-gitlab/templates/compose.yml.j2 @@ -48,8 +48,6 @@ {{ lookup('container_networks') | indent(4) }} {% set service_name = GITLAB_SIDEKIQ_SERVICE_NAME %} - {% set container_healthcheck = 'liveness' %} - {% set container_healthcheck_start_period = '300s' %} {{ service_name }}: {{ lookup('compose_only', 'container_name', GITLAB_SIDEKIQ_CONTAINER) }} {{ lookup('container_image', application_id, service_name) }} @@ -58,7 +56,7 @@ CONFIG_TEMPLATE_DIRECTORY: "/var/opt/gitlab/config/templates" CONFIG_DIRECTORY: "/srv/gitlab/config" command: ["/scripts/wait-for-deps", "/scripts/process-wrapper"] - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id, extra={ GITLAB_MIGRATIONS_SERVICE_NAME: {'condition': 'service_completed_successfully'}, GITLAB_WEBSERVICE_SERVICE_NAME: {'condition': 'service_started'}, diff --git a/roles/web-app-hugo/meta/services.yml b/roles/web-app-hugo/meta/services.yml index 327e06e099..0f445b3de4 100644 --- a/roles/web-app-hugo/meta/services.yml +++ b/roles/web-app-hugo/meta/services.yml @@ -24,6 +24,8 @@ css: enabled: "{{ 'web-svc-css' in group_names }}" shared: "{{ 'web-svc-css' in group_names }}" hugo: + healthcheck: + flavor: wget modes: compose: enabled: true diff --git a/roles/web-app-hugo/templates/compose.yml.j2 b/roles/web-app-hugo/templates/compose.yml.j2 index 50179d2ef2..4a8c3b59c9 100644 --- a/roles/web-app-hugo/templates/compose.yml.j2 +++ b/roles/web-app-hugo/templates/compose.yml.j2 @@ -15,7 +15,7 @@ {{ lookup('container_ports', ['hugo', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-jellyfin/meta/services.yml b/roles/web-app-jellyfin/meta/services.yml index acce729f6c..470f01c9e7 100644 --- a/roles/web-app-jellyfin/meta/services.yml +++ b/roles/web-app-jellyfin/meta/services.yml @@ -52,6 +52,9 @@ jellyfin: http: 8096 local: http: 8088 + healthcheck: + flavor: curl + path: health run_after: - web-app-keycloak - svc-db-openldap diff --git a/roles/web-app-jellyfin/templates/compose.yml.j2 b/roles/web-app-jellyfin/templates/compose.yml.j2 index e59aaeeb3b..613de3761b 100644 --- a/roles/web-app-jellyfin/templates/compose.yml.j2 +++ b/roles/web-app-jellyfin/templates/compose.yml.j2 @@ -1,12 +1,11 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'jellyfin' %} - {% set container_healthcheck = 'health' %} {{ service_name }}: {{ lookup('container_image', application_id, 'jellyfin') }} {{ lookup('compose_only', 'container_name', JELLYFIN_NAME) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_ports', ['jellyfin', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} diff --git a/roles/web-app-jenkins/meta/services.yml b/roles/web-app-jenkins/meta/services.yml index bb661e7a84..013bd9018d 100644 --- a/roles/web-app-jenkins/meta/services.yml +++ b/roles/web-app-jenkins/meta/services.yml @@ -25,6 +25,10 @@ ldap: enabled: "{{ 'svc-db-openldap' in group_names }}" shared: "{{ 'svc-db-openldap' in group_names }}" jenkins: + healthcheck: + flavor: curl + path: login + start_period: 10m modes: compose: enabled: true diff --git a/roles/web-app-jenkins/templates/compose.yml.j2 b/roles/web-app-jenkins/templates/compose.yml.j2 index bd33b1107c..09305b50de 100644 --- a/roles/web-app-jenkins/templates/compose.yml.j2 +++ b/roles/web-app-jenkins/templates/compose.yml.j2 @@ -1,6 +1,4 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {% set container_healthcheck = 'login' %} - {% set container_healthcheck_start_period = '10m' %} {% set service_name = 'jenkins' %} {{ service_name }}: {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} @@ -15,7 +13,7 @@ CASC_JENKINS_CONFIG: /var/jenkins_home/casc.yaml {{ lookup('container_ports', ['jenkins', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'jenkins') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-jira/meta/services.yml b/roles/web-app-jira/meta/services.yml index 5796a5a17b..e90f6bbf58 100644 --- a/roles/web-app-jira/meta/services.yml +++ b/roles/web-app-jira/meta/services.yml @@ -28,6 +28,8 @@ postgres: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-postgres' in group_names }}" jira: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-jira/templates/compose.yml.j2 b/roles/web-app-jira/templates/compose.yml.j2 index bb1f452a38..f6311d683f 100644 --- a/roles/web-app-jira/templates/compose.yml.j2 +++ b/roles/web-app-jira/templates/compose.yml.j2 @@ -11,7 +11,7 @@ hostname: '{{ JIRA_HOSTNAME }}' {{ lookup('container_ports', ['jira', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'jira') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-joomla/meta/services.yml b/roles/web-app-joomla/meta/services.yml index 612df020d0..562e8dfcc5 100644 --- a/roles/web-app-joomla/meta/services.yml +++ b/roles/web-app-joomla/meta/services.yml @@ -33,6 +33,9 @@ mariadb: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-mariadb' in group_names }}" joomla: + healthcheck: + flavor: curl + start_period: 15m modes: compose: enabled: true diff --git a/roles/web-app-joomla/templates/compose.yml.j2 b/roles/web-app-joomla/templates/compose.yml.j2 index 91aef15390..e2985a3e3d 100644 --- a/roles/web-app-joomla/templates/compose.yml.j2 +++ b/roles/web-app-joomla/templates/compose.yml.j2 @@ -1,6 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'joomla' %} - {% set container_healthcheck_start_period = '15m' %} {{ service_name }}: {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} args: @@ -13,7 +12,7 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} {{ lookup('container_ports', ['joomla', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} diff --git a/roles/web-app-keycloak/meta/services.yml b/roles/web-app-keycloak/meta/services.yml index 963c3ee04e..3be2e263b5 100644 --- a/roles/web-app-keycloak/meta/services.yml +++ b/roles/web-app-keycloak/meta/services.yml @@ -30,6 +30,11 @@ email: shared: "{{ 'web-app-mailu' in group_names }}" # nocheck: playwright-service-flag — self-provider keycloak: + healthcheck: + flavor: http_status + path: health/ready + port_key: management + start_period: 180s modes: compose: enabled: true diff --git a/roles/web-app-keycloak/templates/compose.yml.j2 b/roles/web-app-keycloak/templates/compose.yml.j2 index 657c7ff10c..84e0dad140 100644 --- a/roles/web-app-keycloak/templates/compose.yml.j2 +++ b/roles/web-app-keycloak/templates/compose.yml.j2 @@ -1,9 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {# nocheck: container-port-set-unused #} - {% set container_port = lookup('config', application_id, 'services.' ~ entity_name ~ '.ports.internal.management') %} - {% set container_healthcheck = 'health/ready' %} - {% set container_healthcheck_start_period = '180s' %} {% set service_name = 'keycloak' %} {{ service_name }}: {{ lookup('container_image', application_id, 'keycloak') }} @@ -15,7 +11,7 @@ {{ lookup('container_volumes', application_id, 'keycloak') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/http_status.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id, ) }} diff --git a/roles/web-app-listmonk/meta/services.yml b/roles/web-app-listmonk/meta/services.yml index e1245ae364..497bacb922 100644 --- a/roles/web-app-listmonk/meta/services.yml +++ b/roles/web-app-listmonk/meta/services.yml @@ -51,6 +51,9 @@ listmonk: http: 9000 local: http: 8019 + healthcheck: + flavor: wget + path: health public_api_activated: false run_after: - web-app-matomo diff --git a/roles/web-app-listmonk/templates/compose.yml.j2 b/roles/web-app-listmonk/templates/compose.yml.j2 index e82a033596..66b258b710 100644 --- a/roles/web-app-listmonk/templates/compose.yml.j2 +++ b/roles/web-app-listmonk/templates/compose.yml.j2 @@ -1,5 +1,4 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {% set container_healthcheck = 'health' %} {% set service_name = 'listmonk' %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} @@ -10,7 +9,7 @@ {{ lookup('container_volumes', application_id, service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id, ) }} diff --git a/roles/web-app-magento/meta/services.yml b/roles/web-app-magento/meta/services.yml index 39fc7c4b48..43200a3799 100644 --- a/roles/web-app-magento/meta/services.yml +++ b/roles/web-app-magento/meta/services.yml @@ -72,6 +72,8 @@ redis: # nocheck: shared # nocheck: dynamic-flag search: + healthcheck: + flavor: tcp ports: internal: http: 9200 diff --git a/roles/web-app-magento/templates/compose.yml.j2 b/roles/web-app-magento/templates/compose.yml.j2 index 06d7863a23..562c77f86c 100644 --- a/roles/web-app-magento/templates/compose.yml.j2 +++ b/roles/web-app-magento/templates/compose.yml.j2 @@ -37,7 +37,7 @@ - discovery.type=single-node - plugins.security.disabled=true - OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-mastodon/meta/services.yml b/roles/web-app-mastodon/meta/services.yml index 5136d12541..0f7cca7655 100644 --- a/roles/web-app-mastodon/meta/services.yml +++ b/roles/web-app-mastodon/meta/services.yml @@ -65,6 +65,9 @@ mastodon: websocket: 4000 proxy: service_key: mastodon + healthcheck: + flavor: wget + path: health run_after: - web-app-keycloak lifecycle: beta @@ -77,8 +80,18 @@ streaming: mem_limit: 512m pids_limit: 256 min_storage: 309MB + ports: + internal: + http: 4000 + healthcheck: + flavor: wget + path: api/v1/streaming/health sidekiq: name: mastodon-sidekiq + healthcheck: + test: ["CMD-SHELL", "pgrep -f sidekiq || exit 1"] + interval: 1m + timeout: 10s cpus: "0.8" mem_reservation: 1g mem_limit: 1.5g diff --git a/roles/web-app-mastodon/templates/compose.yml.j2 b/roles/web-app-mastodon/templates/compose.yml.j2 index 69f95913e5..8d2186a53e 100644 --- a/roles/web-app-mastodon/templates/compose.yml.j2 +++ b/roles/web-app-mastodon/templates/compose.yml.j2 @@ -1,25 +1,15 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} -{% macro mastodon_service(name, container, image_key, command, ports_key=none, hc_port=none, hc_path=none, hc_test=none, with_volumes=false, after_migrate=true, restart=none) -%} +{% macro mastodon_service(name, container, image_key, command, ports_key=none, healthcheck=true, with_volumes=false, after_migrate=true, restart=none) -%} {% set service_name = name %} {% if restart is not none %}{% set docker_restart_policy = restart %}{% endif %} -{# nocheck: container-port-set-unused #} -{% if hc_port is not none %}{% set container_port = hc_port %}{% endif %} -{% if hc_path is not none %}{% set container_healthcheck = hc_path %}{% endif %} {{ service_name }}: {{ lookup('compose_only', 'container_name', container) }} {{ lookup('container_image', application_id, image_key) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} command: {{ command }} - {% if hc_path is not none %} - {% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} - {% endif %} - {% if hc_test is not none %} - healthcheck: - test: {{ hc_test }} - interval: 1m - timeout: 10s - retries: 3 + {% if healthcheck %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% endif %} {% if ports_key is not none %} {{ lookup('container_ports', ['mastodon', ports_key, DOCKER_BIND_HOST]) | indent(4) }} @@ -37,10 +27,10 @@ {{ lookup('container_networks') | indent(4) }} {% endmacro -%} -{{ mastodon_service(MASTODON_SERVICE_NAME, MASTODON_CONTAINER, 'mastodon', 'bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"', ports_key='http', hc_port=3000, hc_path='health', with_volumes=true) }} -{{ mastodon_service(MASTODON_STREAMING_SERVICE_NAME, MASTODON_STREAMING_CONTAINER, 'streaming', 'node ./streaming', ports_key='websocket', hc_port=4000, hc_path='api/v1/streaming/health') }} -{{ mastodon_service(MASTODON_SIDEKIQ_SERVICE_NAME, MASTODON_SIDEKIQ_CONTAINER, 'mastodon', 'bundle exec sidekiq', hc_test='["CMD-SHELL", "pgrep -f sidekiq || exit 1"]', with_volumes=true) }} -{{ mastodon_service(MASTODON_MIGRATE_SERVICE_NAME, MASTODON_MIGRATE_CONTAINER, 'mastodon', 'bundle exec rails db:prepare', after_migrate=false, restart='on-failure') }} +{{ mastodon_service(MASTODON_SERVICE_NAME, MASTODON_CONTAINER, 'mastodon', 'bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"', ports_key='http', with_volumes=true) }} +{{ mastodon_service(MASTODON_STREAMING_SERVICE_NAME, MASTODON_STREAMING_CONTAINER, 'streaming', 'node ./streaming', ports_key='websocket') }} +{{ mastodon_service(MASTODON_SIDEKIQ_SERVICE_NAME, MASTODON_SIDEKIQ_CONTAINER, 'mastodon', 'bundle exec sidekiq', with_volumes=true) }} +{{ mastodon_service(MASTODON_MIGRATE_SERVICE_NAME, MASTODON_MIGRATE_CONTAINER, 'mastodon', 'bundle exec rails db:prepare', healthcheck=false, after_migrate=false, restart='on-failure') }} {{ lookup('compose_volumes', application_id) }} {{ lookup('compose_networks') }} diff --git a/roles/web-app-matrix/meta/services.yml b/roles/web-app-matrix/meta/services.yml index bf0a7f1cb8..cd722dc127 100644 --- a/roles/web-app-matrix/meta/services.yml +++ b/roles/web-app-matrix/meta/services.yml @@ -36,6 +36,8 @@ postgres: enabled: true # nocheck: dynamic-flag — matrix always needs a database shared: "{{ 'svc-db-postgres' in group_names }}" synapse: + healthcheck: + flavor: curl version: v1.156.0 image: matrixdotorg/synapse name: matrix-synapse @@ -54,6 +56,8 @@ synapse: mem_limit: "2g" pids_limit: 2048 element: + healthcheck: + flavor: wget version: v1.12.23 image: vectorim/element-web name: matrix-element diff --git a/roles/web-app-matrix/templates/flavor/compose/services.yml.j2 b/roles/web-app-matrix/templates/flavor/compose/services.yml.j2 index 1a668fd207..3bf2c00f9c 100644 --- a/roles/web-app-matrix/templates/flavor/compose/services.yml.j2 +++ b/roles/web-app-matrix/templates/flavor/compose/services.yml.j2 @@ -17,7 +17,7 @@ - SYNAPSE_REPORT_STATS=no ports: - "{{ DOCKER_BIND_HOST }}:{{lookup('config', 'web-app-matrix', 'services.synapse.ports.local.http')}}:{{ container_port }}" -{% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% set _synapse_bridge_deps = {} %} {% for item in MATRIX_BRIDGES %} {% set _ = _synapse_bridge_deps.__setitem__('mautrix-' ~ item.bridge_name, {'condition': 'service_healthy'}) %} @@ -34,7 +34,7 @@ {{ lookup('container_volumes', application_id, service_name) | indent(4) }} ports: - "{{ DOCKER_BIND_HOST }}:{{ MATRIX_ELEMENT_PORT }}:{{ container_port }}" -{% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {% for item in MATRIX_BRIDGES %} diff --git a/roles/web-app-mediawiki/meta/services.yml b/roles/web-app-mediawiki/meta/services.yml index f69c7122e6..3199933b0c 100644 --- a/roles/web-app-mediawiki/meta/services.yml +++ b/roles/web-app-mediawiki/meta/services.yml @@ -27,6 +27,9 @@ mariadb: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-mariadb' in group_names }}" mediawiki: + healthcheck: + flavor: tcp + start_period: 5m modes: compose: enabled: true diff --git a/roles/web-app-mediawiki/templates/compose.yml.j2 b/roles/web-app-mediawiki/templates/compose.yml.j2 index 6c84040ba4..a00bdff03f 100644 --- a/roles/web-app-mediawiki/templates/compose.yml.j2 +++ b/roles/web-app-mediawiki/templates/compose.yml.j2 @@ -1,6 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = entity_name %} - {% set container_healthcheck_start_period = '5m' %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} @@ -11,7 +10,7 @@ {{ lookup('container_image', application_id, 'mediawiki') }} {{ lookup('container_volumes', application_id, entity_name) | indent(4) }} {{ lookup('container_ports', ['mediawiki', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} diff --git a/roles/web-app-mig/meta/services.yml b/roles/web-app-mig/meta/services.yml index 312c8ec81f..cca7241698 100644 --- a/roles/web-app-mig/meta/services.yml +++ b/roles/web-app-mig/meta/services.yml @@ -26,6 +26,8 @@ redis: backup: disabled: true mig: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-mig/templates/compose.yml.j2 b/roles/web-app-mig/templates/compose.yml.j2 index 01a409e3e0..60b41b3e28 100644 --- a/roles/web-app-mig/templates/compose.yml.j2 +++ b/roles/web-app-mig/templates/compose.yml.j2 @@ -6,7 +6,7 @@ {{ lookup('compose_only', 'container_name', MIG_CONTAINER) }} {{ lookup('container_ports', ['mig', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} {{ lookup('compose_networks') }} diff --git a/roles/web-app-mobilizon/meta/services.yml b/roles/web-app-mobilizon/meta/services.yml index 50c90121ae..897ad2c3c9 100644 --- a/roles/web-app-mobilizon/meta/services.yml +++ b/roles/web-app-mobilizon/meta/services.yml @@ -30,6 +30,8 @@ postgres: - pg_trgm - unaccent mobilizon: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-mobilizon/templates/compose.yml.j2 b/roles/web-app-mobilizon/templates/compose.yml.j2 index 1aa5343795..2766c5ee89 100644 --- a/roles/web-app-mobilizon/templates/compose.yml.j2 +++ b/roles/web-app-mobilizon/templates/compose.yml.j2 @@ -5,7 +5,7 @@ {{ lookup('compose_only', 'container_name', mobilizon_container) }} {{ lookup('container_volumes', application_id, 'mobilizon') | indent(4) }} {{ lookup('container_ports', ['mobilizon', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-n8n/meta/services.yml b/roles/web-app-n8n/meta/services.yml index b90cd50605..655ddbe10a 100644 --- a/roles/web-app-n8n/meta/services.yml +++ b/roles/web-app-n8n/meta/services.yml @@ -42,6 +42,10 @@ postgres: enabled: true shared: "{{ 'svc-db-postgres' in group_names }}" n8n: + healthcheck: + flavor: wget + path: healthz + start_period: 5m modes: compose: enabled: true diff --git a/roles/web-app-n8n/templates/compose.yml.j2 b/roles/web-app-n8n/templates/compose.yml.j2 index d7d1ab1bbd..cdfda6058b 100644 --- a/roles/web-app-n8n/templates/compose.yml.j2 +++ b/roles/web-app-n8n/templates/compose.yml.j2 @@ -1,14 +1,12 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'n8n' %} - {% set container_healthcheck = 'healthz' %} - {% set container_healthcheck_start_period = '5m' %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_image', application_id, service_name) }} {{ lookup('compose_only', 'container_name', N8N_CONTAINER) }} {{ lookup('container_ports', ['n8n', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-nextcloud/meta/services.yml b/roles/web-app-nextcloud/meta/services.yml index d5f4ddf8df..2b1096ee30 100644 --- a/roles/web-app-nextcloud/meta/services.yml +++ b/roles/web-app-nextcloud/meta/services.yml @@ -100,6 +100,9 @@ nextcloud: lifecycle: beta proxy: name: nextcloud-proxy + healthcheck: + flavor: curl + start_period: 20m image: nginx version: 1.31.2-alpine backup: @@ -141,6 +144,10 @@ talk: ports: internal: signaling: 8081 + healthcheck: + flavor: tcp + port_key: signaling + start_period: 20m whiteboard: name: nextcloud-whiteboard image: ghcr.io/nextcloud-releases/whiteboard @@ -153,6 +160,12 @@ whiteboard: mem_limit: 1g pids_limit: 1024 min_storage: 683MB + ports: + internal: + http: 3002 + healthcheck: + flavor: nc + start_period: 20m # nocheck: playwright-service-flag: infrastructural sub-component (collaborative editing) onlyoffice: bond: 0.5 diff --git a/roles/web-app-nextcloud/templates/compose.yml.j2 b/roles/web-app-nextcloud/templates/compose.yml.j2 index 85a6dc37fb..e821fcda09 100644 --- a/roles/web-app-nextcloud/templates/compose.yml.j2 +++ b/roles/web-app-nextcloud/templates/compose.yml.j2 @@ -1,6 +1,4 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {% set container_healthcheck_start_period = '20m' %} - {% set service_name = NEXTCLOUD_PROXY_SERVICE %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/deploy.yml.j2' %} @@ -11,7 +9,7 @@ {{ lookup('compose_restart') }} {{ lookup('container_ports', ['nextcloud', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name, samples=(groups[application_id] | default([]) | length) if DEPLOYMENT_MODE == 'swarm' else 1) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {% if NEXTCLOUD_HPB_NETWORK_MODE == 'host' %} extra_hosts: @@ -19,6 +17,7 @@ {% endif %} {% set service_name = NEXTCLOUD_SERVICE %} + {% set container_healthcheck_start_period = '20m' %} {{ service_name }}: {{ lookup('container_image', application_id, 'nextcloud') }} {{ lookup('compose_only', 'container_name', NEXTCLOUD_CONTAINER) }} @@ -46,7 +45,7 @@ {% set container_port = NEXTCLOUD_HPB_SIGNALING_PORT %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_image', application_id, 'talk') }} {{ lookup('compose_only', 'container_name', NEXTCLOUD_HPB_CONTAINER) }} init: true @@ -76,7 +75,7 @@ dockerfile: {{ NEXTCLOUD_WHITEBOARD_SERVICE_DOCKERFILE }} {{ lookup('compose_only', 'pull_policy', 'never') }} {{ lookup('container_image', application_id, 'whiteboard') }} - {% include 'roles/sys-svc-container/templates/healthcheck/nc.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_only', 'container_name', NEXTCLOUD_WHITEBOARD_CONTAINER) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} environment: diff --git a/roles/web-app-nextcloud/vars/main.yml b/roles/web-app-nextcloud/vars/main.yml index d0a0f68001..7e3ad575bb 100644 --- a/roles/web-app-nextcloud/vars/main.yml +++ b/roles/web-app-nextcloud/vars/main.yml @@ -125,7 +125,7 @@ NEXTCLOUD_WHITEBOARD_CONTAINER: "{{ lookup('config', application_id, 'services.' NEXTCLOUD_WHITEBOARD_IMAGE: "{{ lookup('config', application_id, 'services.' ~ NEXTCLOUD_WHITEBOARD_SERVICE ~'.image') }}" NEXTCLOUD_WHITEBOARD_VERSION: "{{ lookup('config', application_id, 'services.' ~ NEXTCLOUD_WHITEBOARD_SERVICE ~'.version') }}" NEXTCLOUD_WHITEBOARD_ENABLED: "{{ lookup('config', application_id, 'addons.' ~ NEXTCLOUD_WHITEBOARD_SERVICE ~'.enabled') }}" -NEXTCLOUD_WHITEBOARD_PORT_INTERNAL: "3002" +NEXTCLOUD_WHITEBOARD_PORT_INTERNAL: "{{ lookup('config', application_id, 'services.' ~ NEXTCLOUD_WHITEBOARD_SERVICE ~ '.ports.internal.http') }}" NEXTCLOUD_WHITEBOARD_JWT: "{{ lookup('config', application_id, 'credentials.' ~ NEXTCLOUD_WHITEBOARD_SERVICE ~'_jwt_secret') }}" NEXTCLOUD_WHITEBOARD_LOCATION: "/whiteboard/" NEXTCLOUD_WHITEBOARD_URL: "{{ [ NEXTCLOUD_URL, NEXTCLOUD_WHITEBOARD_LOCATION ] | url_join }}" diff --git a/roles/web-app-odoo/meta/services.yml b/roles/web-app-odoo/meta/services.yml index 8daa973084..f3f26352de 100644 --- a/roles/web-app-odoo/meta/services.yml +++ b/roles/web-app-odoo/meta/services.yml @@ -31,6 +31,10 @@ postgres: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-postgres' in group_names }}" odoo: + healthcheck: + flavor: tcp + path: web/health + start_period: 5m modes: compose: enabled: true diff --git a/roles/web-app-odoo/templates/compose.yml.j2 b/roles/web-app-odoo/templates/compose.yml.j2 index 7d201af6e4..0f40085f07 100644 --- a/roles/web-app-odoo/templates/compose.yml.j2 +++ b/roles/web-app-odoo/templates/compose.yml.j2 @@ -1,8 +1,6 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set container_port = lookup('config', application_id, 'services.' ~ entity_name ~ '.ports.internal.http') %} - {% set container_healthcheck = 'web/health' %} - {% set container_healthcheck_start_period = '5m' %} {% set service_name = ODOO_SERVICE %} {{ service_name }}: {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} @@ -17,7 +15,7 @@ stop_signal: SIGTERM stop_grace_period: 30s {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_ports', ['odoo', 'http', DOCKER_BIND_HOST], ['odoo', 'websocket', DOCKER_BIND_HOST]) | indent(4) }} diff --git a/roles/web-app-openproject/meta/services.yml b/roles/web-app-openproject/meta/services.yml index e1c89101a9..6caef89c15 100644 --- a/roles/web-app-openproject/meta/services.yml +++ b/roles/web-app-openproject/meta/services.yml @@ -37,6 +37,9 @@ seaweedfs: shared: "{{ 'web-app-seaweedfs' in group_names }}" web: name: openproject-web + healthcheck: + flavor: curl + path: health_checks/default ports: internal: http: 8080 diff --git a/roles/web-app-openproject/templates/compose.yml.j2 b/roles/web-app-openproject/templates/compose.yml.j2 index 231f02f79c..d41163f4b1 100644 --- a/roles/web-app-openproject/templates/compose.yml.j2 +++ b/roles/web-app-openproject/templates/compose.yml.j2 @@ -29,7 +29,6 @@ x-op-app: &app {{ lookup('container_volumes', application_id, 'proxy') | indent(4) }} {% set service_name = OPENPROJECT_WEB_SERVICE %} - {% set container_healthcheck = 'health_checks/default' %} {{ service_name }}: <<: *app {% include 'roles/sys-svc-container/templates/base.yml.j2' %} @@ -40,7 +39,7 @@ x-op-app: &app 'cache': {'condition': 'service_started'}, OPENPROJECT_SEEDER_SERVICE: {'condition': 'service_started'}, }) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_volumes', application_id, OPENPROJECT_WEB_SERVICE) | indent(4) }} {% set service_name = 'worker' %} diff --git a/roles/web-app-peertube/meta/services.yml b/roles/web-app-peertube/meta/services.yml index 714722d1ab..3f667de508 100644 --- a/roles/web-app-peertube/meta/services.yml +++ b/roles/web-app-peertube/meta/services.yml @@ -50,6 +50,8 @@ seaweedfs: public: true # nocheck: playwright-service-flag: shared provider entity; the app itself is covered by this role's own Playwright spec peertube: + healthcheck: + flavor: tcp modes: compose: enabled: true diff --git a/roles/web-app-peertube/templates/compose.yml.j2 b/roles/web-app-peertube/templates/compose.yml.j2 index a7ac198252..76c894623b 100644 --- a/roles/web-app-peertube/templates/compose.yml.j2 +++ b/roles/web-app-peertube/templates/compose.yml.j2 @@ -26,6 +26,6 @@ nproc: 8192 {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} {{ lookup('compose_networks') }} diff --git a/roles/web-app-penpot/meta/services.yml b/roles/web-app-penpot/meta/services.yml index 7b41b74a7e..e83ae67df4 100644 --- a/roles/web-app-penpot/meta/services.yml +++ b/roles/web-app-penpot/meta/services.yml @@ -51,6 +51,8 @@ seaweedfs: enabled: "{{ 'web-app-seaweedfs' in group_names }}" shared: "{{ 'web-app-seaweedfs' in group_names }}" penpot: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-penpot/templates/compose.yml.j2 b/roles/web-app-penpot/templates/compose.yml.j2 index 6e18f62703..0ea53b13fc 100644 --- a/roles/web-app-penpot/templates/compose.yml.j2 +++ b/roles/web-app-penpot/templates/compose.yml.j2 @@ -1,7 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {# nocheck: container-port-set-unused #} - {% set container_port = PENPOT_FRONTEND_INTERNAL_PORT %} {% set service_name = PENPOT_FRONTEND_SERVICE %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} @@ -13,7 +11,7 @@ - 'until getent hosts {{ PENPOT_BACKEND_SERVICE }} >/dev/null 2>&1 && getent hosts {{ PENPOT_EXPORTER_SERVICE }} >/dev/null 2>&1; do sleep 1; done; exec nginx -g "daemon off;"' {{ lookup('container_ports', ['penpot', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', 'penpot') | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_depends_on', application_id, extra={ PENPOT_BACKEND_SERVICE: {'condition': 'service_started'}, diff --git a/roles/web-app-penpot/vars/main.yml b/roles/web-app-penpot/vars/main.yml index bf6d09fbb0..9f0e08d3e5 100644 --- a/roles/web-app-penpot/vars/main.yml +++ b/roles/web-app-penpot/vars/main.yml @@ -13,7 +13,6 @@ PENPOT_EXPORTER_SERVICE: "exporter" PENPOT_BACKEND_CONTAINER_ADDRESS: "{{ lookup('container_address', application_id, PENPOT_BACKEND_SERVICE) }}" -PENPOT_FRONTEND_INTERNAL_PORT: "{{ lookup('config', application_id, 'services.penpot.ports.internal.http') }}" PENPOT_BACKEND_INTERNAL_PORT: "{{ lookup('config', application_id, 'services.backend.ports.internal.http') }}" PENPOT_EXPORTER_INTERNAL_PORT: "{{ lookup('config', application_id, 'services.exporter.ports.internal.http') }}" diff --git a/roles/web-app-pgadmin/meta/services.yml b/roles/web-app-pgadmin/meta/services.yml index 9e954f89ff..4ec661dcb3 100644 --- a/roles/web-app-pgadmin/meta/services.yml +++ b/roles/web-app-pgadmin/meta/services.yml @@ -1,6 +1,9 @@ --- # nocheck: seaweedfs-required — object storage not implemented for this role pgadmin: + healthcheck: + flavor: wget + start_period: 10m modes: compose: enabled: true diff --git a/roles/web-app-pgadmin/templates/compose.yml.j2 b/roles/web-app-pgadmin/templates/compose.yml.j2 index dd8e885036..e2d0bf4405 100644 --- a/roles/web-app-pgadmin/templates/compose.yml.j2 +++ b/roles/web-app-pgadmin/templates/compose.yml.j2 @@ -1,7 +1,6 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = entity_name %} - {% set container_healthcheck_start_period = '10m' %} {{ service_name }}: {{ lookup('container_image', application_id, 'pgadmin') }} {{ lookup('compose_only', 'container_name', entity_name) }} @@ -9,7 +8,7 @@ {{ lookup('container_ports', ['pgadmin', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_volumes', application_id, entity_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-phpmyadmin/meta/services.yml b/roles/web-app-phpmyadmin/meta/services.yml index 2d2c99654b..6548f6d632 100644 --- a/roles/web-app-phpmyadmin/meta/services.yml +++ b/roles/web-app-phpmyadmin/meta/services.yml @@ -17,6 +17,8 @@ mariadb: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-mariadb' in group_names }}" phpmyadmin: + healthcheck: + flavor: tcp modes: compose: enabled: true diff --git a/roles/web-app-phpmyadmin/templates/compose.yml.j2 b/roles/web-app-phpmyadmin/templates/compose.yml.j2 index 0bbcd39c3e..b4efdbdd8d 100644 --- a/roles/web-app-phpmyadmin/templates/compose.yml.j2 +++ b/roles/web-app-phpmyadmin/templates/compose.yml.j2 @@ -8,7 +8,7 @@ {{ lookup('container_ports', ['phpmyadmin', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-pihole/meta/services.yml b/roles/web-app-pihole/meta/services.yml index cccd7bd0ea..e5e1539081 100644 --- a/roles/web-app-pihole/meta/services.yml +++ b/roles/web-app-pihole/meta/services.yml @@ -54,6 +54,8 @@ sso: allowed_groups: - "{{ lookup('rbac_group_path', application_id='web-app-pihole', role='administrator') }}" pihole: + healthcheck: + flavor: tcp modes: compose: enabled: true diff --git a/roles/web-app-pihole/templates/compose.yml.j2 b/roles/web-app-pihole/templates/compose.yml.j2 index 373fa081f7..43e7357759 100644 --- a/roles/web-app-pihole/templates/compose.yml.j2 +++ b/roles/web-app-pihole/templates/compose.yml.j2 @@ -14,7 +14,7 @@ cap_add: - NET_ADMIN {{ lookup('container_volumes', application_id, 'pihole') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-postmarks/meta/services.yml b/roles/web-app-postmarks/meta/services.yml index 99be75c5de..e345b3fc53 100644 --- a/roles/web-app-postmarks/meta/services.yml +++ b/roles/web-app-postmarks/meta/services.yml @@ -38,6 +38,8 @@ prometheus: enabled: "{{ 'web-app-prometheus' in group_names }}" shared: "{{ 'web-app-prometheus' in group_names }}" postmarks: + healthcheck: + flavor: tcp modes: compose: enabled: true diff --git a/roles/web-app-postmarks/templates/compose.yml.j2 b/roles/web-app-postmarks/templates/compose.yml.j2 index 8e694c26d2..991ec06280 100644 --- a/roles/web-app-postmarks/templates/compose.yml.j2 +++ b/roles/web-app-postmarks/templates/compose.yml.j2 @@ -10,7 +10,7 @@ {{ lookup('compose_only', 'container_name', POSTMARKS_CONTAINER) }} hostname: "{{ container_hostname }}" {{ lookup('container_ports', ['postmarks', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-pretix/meta/services.yml b/roles/web-app-pretix/meta/services.yml index 915ad4f9ff..fd9137b3f2 100644 --- a/roles/web-app-pretix/meta/services.yml +++ b/roles/web-app-pretix/meta/services.yml @@ -40,6 +40,8 @@ postgres: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-postgres' in group_names }}" pretix: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-pretix/templates/compose.yml.j2 b/roles/web-app-pretix/templates/compose.yml.j2 index c94edfd2e2..697e364694 100644 --- a/roles/web-app-pretix/templates/compose.yml.j2 +++ b/roles/web-app-pretix/templates/compose.yml.j2 @@ -12,7 +12,7 @@ command: ["all"] {{ lookup('container_ports', ['pretix', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'pretix') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-semaphore/meta/services.yml b/roles/web-app-semaphore/meta/services.yml index 8693c84302..277688d14a 100644 --- a/roles/web-app-semaphore/meta/services.yml +++ b/roles/web-app-semaphore/meta/services.yml @@ -39,6 +39,9 @@ postgres: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-postgres' in group_names }}" semaphore: + healthcheck: + flavor: wget + path: api/ping modes: compose: enabled: true diff --git a/roles/web-app-semaphore/templates/compose.yml.j2 b/roles/web-app-semaphore/templates/compose.yml.j2 index 9d22e40b9f..117600a5ca 100644 --- a/roles/web-app-semaphore/templates/compose.yml.j2 +++ b/roles/web-app-semaphore/templates/compose.yml.j2 @@ -1,12 +1,11 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'semaphore' %} - {% set container_healthcheck = 'api/ping' %} {{ service_name }}: {{ lookup('container_image', application_id, 'semaphore') }} {{ lookup('compose_only', 'container_name', SEMAPHORE_NAME) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_ports', ['semaphore', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/wget.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} diff --git a/roles/web-app-sphinx/meta/services.yml b/roles/web-app-sphinx/meta/services.yml index 86565ace1a..9f8fc42321 100644 --- a/roles/web-app-sphinx/meta/services.yml +++ b/roles/web-app-sphinx/meta/services.yml @@ -35,6 +35,8 @@ sphinx: http: 8000 local: http: 8036 + healthcheck: + flavor: curl run_after: - web-app-matomo lifecycle: beta diff --git a/roles/web-app-sphinx/templates/compose.yml.j2 b/roles/web-app-sphinx/templates/compose.yml.j2 index 9820e0b8dc..0e6a0d365e 100644 --- a/roles/web-app-sphinx/templates/compose.yml.j2 +++ b/roles/web-app-sphinx/templates/compose.yml.j2 @@ -5,7 +5,7 @@ {{ lookup('container_image', application_id, 'sphinx') }} {{ lookup('compose_only', 'container_name', SPHINX_CONTAINER) }} {{ lookup('container_ports', ['sphinx', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-app-suitecrm/meta/services.yml b/roles/web-app-suitecrm/meta/services.yml index 769d7830e3..63ec2057fe 100644 --- a/roles/web-app-suitecrm/meta/services.yml +++ b/roles/web-app-suitecrm/meta/services.yml @@ -34,6 +34,9 @@ mariadb: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-mariadb' in group_names }}" suitecrm: + healthcheck: + flavor: curl + start_period: 20m modes: compose: enabled: true diff --git a/roles/web-app-suitecrm/templates/compose.yml.j2 b/roles/web-app-suitecrm/templates/compose.yml.j2 index 44c0e9c6e5..f6a78565b2 100644 --- a/roles/web-app-suitecrm/templates/compose.yml.j2 +++ b/roles/web-app-suitecrm/templates/compose.yml.j2 @@ -1,6 +1,4 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {% set container_healthcheck_start_period = '20m' %} - {% set service_name = SUITECRM_SERVICE %} {{ service_name }}: {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} @@ -21,7 +19,7 @@ stop_signal: SIGTERM stop_grace_period: 30s {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_ports', ['suitecrm', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-taiga/meta/services.yml b/roles/web-app-taiga/meta/services.yml index 43d49a3e20..1d01ebe468 100644 --- a/roles/web-app-taiga/meta/services.yml +++ b/roles/web-app-taiga/meta/services.yml @@ -68,6 +68,11 @@ async: mem_limit: 1.5g pids_limit: 512 front: + healthcheck: + flavor: http + ports: + internal: + http: 80 image: node version: 26-alpine cpus: "0.3" @@ -75,6 +80,11 @@ front: mem_limit: 512m pids_limit: 256 gateway: + healthcheck: + flavor: http + ports: + internal: + http: 80 image: nginx version: alpine cpus: "0.3" diff --git a/roles/web-app-taiga/templates/compose.yml.j2 b/roles/web-app-taiga/templates/compose.yml.j2 index ad4fac4744..8bc444ff06 100644 --- a/roles/web-app-taiga/templates/compose.yml.j2 +++ b/roles/web-app-taiga/templates/compose.yml.j2 @@ -80,8 +80,6 @@ build: taiga: {% set service_name = TAIGA_FRONT_SERVICE %} - {# nocheck: container-port-set-unused #} - {% set container_port = lookup('config', application_id, 'services.' ~ entity_name ~ '.ports.internal.http') %} {{ service_name }}: {{ lookup('compose_only', 'container_name', TAIGA_CONTAINER ~ '-' ~ service_name) }} {% if TAIGA_OIDC_ENABLED | bool %} @@ -94,7 +92,7 @@ build: {{ lookup('container_image', application_id, 'front', image='taigaio/taiga-front', version=TAIGA_VERSION) }} {% endif %} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% include 'roles/sys-svc-container/templates/healthcheck/http.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} @@ -152,7 +150,7 @@ build: {{ lookup('container_ports', ['taiga', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% include 'roles/sys-svc-container/templates/healthcheck/http.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} taiga: diff --git a/roles/web-app-wordpress/meta/services.yml b/roles/web-app-wordpress/meta/services.yml index 0e0dc1aad6..855c7569d4 100644 --- a/roles/web-app-wordpress/meta/services.yml +++ b/roles/web-app-wordpress/meta/services.yml @@ -27,6 +27,8 @@ discourse: enabled: "{{ 'web-app-discourse' in group_names }}" shared: "{{ 'web-app-discourse' in group_names }}" wordpress: + healthcheck: + flavor: msmtp_curl modes: compose: enabled: true diff --git a/roles/web-app-wordpress/templates/compose.yml.j2 b/roles/web-app-wordpress/templates/compose.yml.j2 index 1430b73f11..ee3356499f 100644 --- a/roles/web-app-wordpress/templates/compose.yml.j2 +++ b/roles/web-app-wordpress/templates/compose.yml.j2 @@ -12,7 +12,7 @@ {{ lookup('container_ports', ['wordpress', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', application_id, 'wordpress') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/msmtp_curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-xwiki/meta/services.yml b/roles/web-app-xwiki/meta/services.yml index 3456073003..094dad57ff 100644 --- a/roles/web-app-xwiki/meta/services.yml +++ b/roles/web-app-xwiki/meta/services.yml @@ -40,6 +40,8 @@ postgres: shared: "{{ 'svc-db-postgres' in group_names }}" # nocheck: playwright-service-flag: shared provider entity; the app itself is covered by this role's own Playwright spec xwiki: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-app-xwiki/templates/compose.yml.j2 b/roles/web-app-xwiki/templates/compose.yml.j2 index b9e9f1cc88..8ba8f82c2c 100644 --- a/roles/web-app-xwiki/templates/compose.yml.j2 +++ b/roles/web-app-xwiki/templates/compose.yml.j2 @@ -34,7 +34,7 @@ -Dxwiki.authentication.authclass=com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl {% endif %} {{ lookup('container_volumes', application_id, 'xwiki') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-yourls/meta/services.yml b/roles/web-app-yourls/meta/services.yml index b5e993ec7e..71755425c6 100644 --- a/roles/web-app-yourls/meta/services.yml +++ b/roles/web-app-yourls/meta/services.yml @@ -34,6 +34,9 @@ yourls: http: 8006 internal: http: 8080 + healthcheck: + flavor: curl + path: "{{ (lookup('config', 'web-app-yourls', 'server.locations.admin') | regex_replace('^/+', '') | regex_replace('/+$', '')) ~ '/' }}" run_after: - web-app-matomo - web-app-keycloak diff --git a/roles/web-app-yourls/templates/compose.yml.j2 b/roles/web-app-yourls/templates/compose.yml.j2 index a9224e5939..3555dd100d 100644 --- a/roles/web-app-yourls/templates/compose.yml.j2 +++ b/roles/web-app-yourls/templates/compose.yml.j2 @@ -1,6 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} {% set service_name = 'yourls' %} - {% set container_healthcheck = (YOURLS_ADMIN_LOCATION | regex_replace('^/+', '') | regex_replace('/+$', '')) ~ '/' %} {{ service_name }}: {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} args: @@ -10,7 +9,7 @@ {{ lookup('compose_only', 'container_name', YOURLS_CONTAINER) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_ports', ['yourls', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-svc-collabora/meta/services.yml b/roles/web-svc-collabora/meta/services.yml index b3f779c734..b2ce512a09 100644 --- a/roles/web-svc-collabora/meta/services.yml +++ b/roles/web-svc-collabora/meta/services.yml @@ -12,6 +12,9 @@ redis: enabled: false shared: "{{ 'svc-db-redis' in group_names }}" collabora: + healthcheck: + flavor: tcp + path: hosting/discovery modes: compose: enabled: true diff --git a/roles/web-svc-collabora/templates/compose.yml.j2 b/roles/web-svc-collabora/templates/compose.yml.j2 index a28bf0d0d9..79c2609c1f 100644 --- a/roles/web-svc-collabora/templates/compose.yml.j2 +++ b/roles/web-svc-collabora/templates/compose.yml.j2 @@ -1,6 +1,5 @@ {% include 'roles/sys-svc-compose/templates/base.yml.j2' %} - {% set container_healthcheck = COLLABORA_DISCOVERY_PATH | regex_replace('^/+', '') %} {% set service_name = 'collabora' %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} @@ -17,7 +16,7 @@ - SETGID - FOWNER {{ lookup('container_ports', ['collabora', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-svc-logout/meta/services.yml b/roles/web-svc-logout/meta/services.yml index d4cbfb1711..fbd1ff0cd2 100644 --- a/roles/web-svc-logout/meta/services.yml +++ b/roles/web-svc-logout/meta/services.yml @@ -1,6 +1,8 @@ --- # nocheck: playwright-service-flag — self-provider; injection presence is asserted per consumer via roles_with_service('logout') logout: + healthcheck: + flavor: tcp modes: compose: enabled: true diff --git a/roles/web-svc-logout/templates/compose.yml.j2 b/roles/web-svc-logout/templates/compose.yml.j2 index 7a65445b90..24a41065c6 100644 --- a/roles/web-svc-logout/templates/compose.yml.j2 +++ b/roles/web-svc-logout/templates/compose.yml.j2 @@ -6,7 +6,7 @@ {{ lookup('compose_only', 'container_name', LOGOUT_CONTAINER) }} {{ lookup('container_ports', ['logout', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/roles/web-svc-onlyoffice/meta/services.yml b/roles/web-svc-onlyoffice/meta/services.yml index 1a75decbfc..e7cd0b9601 100644 --- a/roles/web-svc-onlyoffice/meta/services.yml +++ b/roles/web-svc-onlyoffice/meta/services.yml @@ -20,6 +20,8 @@ postgres: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-postgres' in group_names }}" onlyoffice: + healthcheck: + flavor: curl modes: compose: enabled: true diff --git a/roles/web-svc-onlyoffice/templates/compose.yml.j2 b/roles/web-svc-onlyoffice/templates/compose.yml.j2 index 01d287ccad..248aa62a3c 100644 --- a/roles/web-svc-onlyoffice/templates/compose.yml.j2 +++ b/roles/web-svc-onlyoffice/templates/compose.yml.j2 @@ -6,7 +6,7 @@ {{ lookup('container_image', application_id, 'onlyoffice') }} {{ lookup('compose_only', 'container_name', ONLYOFFICE_CONTAINER) }} {{ lookup('container_ports', ['onlyoffice', 'http', DOCKER_BIND_HOST]) | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_volumes', application_id, 'onlyoffice') | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} diff --git a/roles/web-svc-simpleicons/meta/services.yml b/roles/web-svc-simpleicons/meta/services.yml index 5ca61f1132..6a8c7b08ca 100644 --- a/roles/web-svc-simpleicons/meta/services.yml +++ b/roles/web-svc-simpleicons/meta/services.yml @@ -55,6 +55,8 @@ simpleicons: http: 3000 proxy: service_key: simpleicons + healthcheck: + flavor: curl lifecycle: beta prometheus: bond: 1 diff --git a/roles/web-svc-simpleicons/templates/compose.yml.j2 b/roles/web-svc-simpleicons/templates/compose.yml.j2 index a19562f5c5..5ee573b673 100644 --- a/roles/web-svc-simpleicons/templates/compose.yml.j2 +++ b/roles/web-svc-simpleicons/templates/compose.yml.j2 @@ -11,7 +11,7 @@ {{ lookup('container_ports', ['simpleicons', 'http', DOCKER_BIND_HOST]) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_networks') | indent(4) }} - {% include 'roles/sys-svc-container/templates/healthcheck/curl.yml.j2' %} + {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('compose_volumes', application_id) }} diff --git a/tests/unit/utils/docker/test_healthcheck.py b/tests/unit/utils/docker/test_healthcheck.py new file mode 100644 index 0000000000..a4f5f3f7a8 --- /dev/null +++ b/tests/unit/utils/docker/test_healthcheck.py @@ -0,0 +1,150 @@ +import unittest + +from utils.cache.yaml import load_yaml_str +from utils.docker.healthcheck import PROBES, Curl, HttpStatus, MsmtpCurl, Nc, Tcp, build + + +def probe(flavor, **context): + return PROBES[flavor](**context).test() + + +def block(flavor, overrides=None, **context): + return load_yaml_str(build(flavor, overrides or {}, **context))["healthcheck"] + + +class TestCurl(unittest.TestCase): + def test_single_sample_uses_the_exec_form(self): + self.assertEqual( + ["CMD", "curl", "-f", "http://127.0.0.1:80/"], + probe("curl", port=80, path="", hostname=None, samples=1), + ) + + def test_an_empty_port_is_left_out_of_the_url(self): + self.assertEqual("http://127.0.0.1/", probe("curl", port="")[-1]) + + def test_the_path_is_appended_without_a_second_slash(self): + self.assertEqual( + "http://127.0.0.1:80/health/ready", + probe("curl", port=80, path="health/ready")[-1], + ) + + def test_a_hostname_becomes_a_header_argument(self): + self.assertEqual( + ["CMD", "curl", "-f", "-H", "Host: app.example", "http://127.0.0.1:80/"], + probe("curl", port=80, hostname="app.example"), + ) + + def test_sampling_chains_one_request_per_replica_in_a_single_probe(self): + """retries counts consecutive failures, so a streak cannot see (N-1)/N loss.""" + chained = probe("curl", port=80, samples=3) + self.assertEqual("CMD-SHELL", chained[0]) + self.assertEqual(3, chained[1].count("curl -f")) + + def test_sampling_keeps_the_host_header(self): + self.assertIn( + "-H 'Host: a.example'", + probe("curl", port=80, hostname="a.example", samples=2)[1], + ) + + +class TestOtherFlavors(unittest.TestCase): + def test_wget_spiders_the_url_with_the_proxy_off(self): + self.assertEqual( + ["CMD", "wget", "--spider", "--proxy=off", "http://127.0.0.1:8080/ready"], + probe("wget", port=8080, path="ready"), + ) + + def test_http_falls_back_from_wget_to_curl(self): + self.assertEqual( + [ + "CMD-SHELL", + ( + "wget -qO- http://127.0.0.1:8080/ >/dev/null " + "|| curl -fsS http://127.0.0.1:8080/ >/dev/null" + ), + ], + probe("http", port=8080), + ) + + def test_nc_probes_the_port_only(self): + self.assertEqual( + ["CMD-SHELL", "nc -z localhost 5432 || exit 1"], probe("nc", port=5432) + ) + + def test_tcp_speaks_http_over_a_bash_socket(self): + argv = probe("tcp", port=8080, path="") + self.assertEqual(["CMD", "bash", "-c"], argv[:3]) + self.assertIn("exec 3<>/dev/tcp/localhost/8080", argv[3]) + self.assertIn("grep -q 'HTTP/1'", argv[3]) + + def test_tcp_keeps_the_escapes_the_shell_needs(self): + """echo -e must receive backslash escapes, not real newlines.""" + self.assertIn("\\r\\n", probe("tcp", port=80)[3]) + + def test_http_status_demands_a_2xx_or_3xx_status_line(self): + argv = probe("http_status", port=80, path="health") + self.assertIn("GET /health HTTP/1.1", argv[3]) + self.assertIn("[23][0-9][0-9]", argv[3]) + + def test_msmtp_curl_sends_one_mail_and_then_only_probes(self): + argv = probe( + "msmtp_curl", + port=80, + email_enabled=True, + domain="app.example", + blackhole="void@example", + ) + self.assertIn("if [ ! -f /tmp/email_sent ]", argv[1]) + self.assertIn("msmtp -t void@example", argv[1]) + self.assertTrue(argv[1].endswith("curl -f http://127.0.0.1:80/ || exit 1")) + + def test_msmtp_curl_drops_the_mail_branch_when_email_is_disabled(self): + """An SMTP outage must not flap the container into unhealthy.""" + self.assertEqual( + ["CMD-SHELL", "curl -f http://127.0.0.1:80/ || exit 1"], + probe("msmtp_curl", port=80, email_enabled=False), + ) + + +class TestBuild(unittest.TestCase): + def test_each_flavor_brings_its_own_timings(self): + self.assertEqual("10s", block("curl", port=80)["timeout"]) + self.assertEqual("3s", block("nc", port=80)["timeout"]) + self.assertEqual("120s", block("msmtp_curl", port=80)["start_period"]) + + def test_the_service_entry_overrides_any_timing(self): + got = block("curl", {"start_period": "20m", "retries": 9}, port=80) + self.assertEqual( + ("20m", 9, "1m"), (got["start_period"], got["retries"], got["interval"]) + ) + + def test_an_empty_flavor_takes_the_explicit_test_argv(self): + self.assertEqual(["CMD", "true"], block("", test=["CMD", "true"])["test"]) + + def test_output_starts_at_column_zero_so_callers_indent_it(self): + self.assertTrue(build("curl", {}, port=80).startswith("healthcheck:")) + + def test_output_carries_no_trailing_newline(self): + self.assertFalse(build("curl", {}, port=80).endswith("\n")) + + def test_every_flavor_names_itself_in_the_registry(self): + self.assertEqual( + {"curl", "wget", "http", "http_status", "nc", "tcp", "msmtp_curl"}, + set(PROBES), + ) + self.assertTrue(all(key == cls.flavor for key, cls in PROBES.items())) + + def test_http_status_inherits_the_request_builder_from_tcp(self): + self.assertTrue(issubclass(HttpStatus, Tcp)) + self.assertNotIn("[23][0-9][0-9]", probe("tcp", port=80)) + + def test_probes_share_one_url_builder(self): + self.assertEqual( + Curl(port=9, path="x").url, + Nc(port=9, path="x").url, + MsmtpCurl(port=9, path="x").url, + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/utils/cache/yaml.py b/utils/cache/yaml.py index c801ba4bfe..eb8b64049e 100644 --- a/utils/cache/yaml.py +++ b/utils/cache/yaml.py @@ -177,6 +177,7 @@ def dump_yaml_str( *, sort_keys: bool = False, default_flow_style: bool = False, + width: int | None = None, ) -> str: """Serialise *data* to a YAML string. @@ -186,9 +187,16 @@ def dump_yaml_str( helper exists so callers don't have to ``import yaml`` just to call ``yaml.safe_dump`` — keeping every YAML touchpoint in ``utils.cache.yaml``. + + Args: + data: the structure to serialise. + sort_keys: emit mapping keys in sorted order. + default_flow_style: emit collections inline instead of block style. + width: column to wrap long scalars at, None for the PyYAML default. """ + extra = {} if width is None else {"width": width} return yaml.safe_dump( # nocheck: direct-yaml — this module IS the cache. - data, sort_keys=sort_keys, default_flow_style=default_flow_style + data, sort_keys=sort_keys, default_flow_style=default_flow_style, **extra ) diff --git a/utils/docker/healthcheck.py b/utils/docker/healthcheck.py new file mode 100644 index 0000000000..7b6e0dd07e --- /dev/null +++ b/utils/docker/healthcheck.py @@ -0,0 +1,213 @@ +"""Container healthcheck probes, one class per flavor. + +Pure and Ansible free: the lookup plugin resolves a service's configuration +and hands it to :func:`build`, which picks the flavor and renders the +compose ``healthcheck`` mapping. + +All probes target the loopback inside the container, so they prove that +this container serves, not that some replica somewhere does. +""" + +from __future__ import annotations + +from typing import Any, ClassVar + +from utils.cache.yaml import dump_yaml_str + +_HTTP_REQUEST = ( + "echo -e 'GET /{path} HTTP/1.1\\r\\nHost: localhost\\r\\n" + "Connection: close\\r\\n\\r\\n' >&3" +) + + +class Probe: + """Base for every flavor: timings plus the argv docker executes.""" + + flavor: ClassVar[str] = "" + interval: ClassVar[str] = "30s" + timeout: ClassVar[str] = "5s" + retries: ClassVar[int] = 3 + start_period: ClassVar[str] = "30s" + + def __init__(self, **context: Any) -> None: + self.port = context.get("port", "") + self.path = context.get("path", "") + self.hostname = context.get("hostname") + self.samples = context.get("samples", 1) + self.context = context + + @property + def url(self) -> str: + return f"http://127.0.0.1{f':{self.port}' if self.port else ''}/{self.path}" + + def test(self) -> list[str]: + raise NotImplementedError + + def block(self, overrides: dict[str, Any]) -> dict[str, Any]: + """Assemble the healthcheck mapping. + + Args: + overrides: service level values that win over the flavor defaults. + """ + block: dict[str, Any] = {"test": self.test()} + for key in ("interval", "timeout", "retries", "start_period"): + block[key] = overrides.get(key, getattr(self, key)) + return block + + +class Custom(Probe): + """A service that spells its probe out instead of picking a flavor.""" + + flavor = "custom" + + def test(self) -> list[str]: + return list(self.context["test"]) + + +class Curl(Probe): + """curl against the loopback, optionally sampling the whole replica pool. + + ``retries`` counts CONSECUTIVE failures, and a request that leaves the + container is load balanced across the service VIP. With N replicas and + one of them alive, a round robin never produces more than N-1 failures + in a row, so a streak based check is arithmetically blind to losing all + but one backend. Chaining ``samples`` requests into a single probe makes + one probe cover the whole pool instead. + """ + + flavor = "curl" + interval = "1m" + timeout = "10s" + + def test(self) -> list[str]: + if self.samples > 1: + host = f"-H 'Host: {self.hostname}' " if self.hostname else "" + return [ + "CMD-SHELL", + " && ".join([f"curl -f {host}{self.url}"] * self.samples), + ] + argv = ["CMD", "curl", "-f"] + if self.hostname: + argv += ["-H", f"Host: {self.hostname}"] + return [*argv, self.url] + + +class Wget(Probe): + flavor = "wget" + interval = "1m" + timeout = "10s" + + def test(self) -> list[str]: + return ["CMD", "wget", "--spider", "--proxy=off", self.url] + + +class Http(Probe): + """Whichever of wget or curl the image happens to ship.""" + + flavor = "http" + retries = 5 + start_period = "20s" + + def test(self) -> list[str]: + return [ + "CMD-SHELL", + f"wget -qO- {self.url} >/dev/null || curl -fsS {self.url} >/dev/null", + ] + + +class Tcp(Probe): + """Speaks HTTP over a bash socket, for images without curl or wget.""" + + flavor = "tcp" + + def request(self) -> str: + return _HTTP_REQUEST.format(path=self.path) + + def test(self) -> list[str]: + return [ + "CMD", + "bash", + "-c", + ( + f"exec 3<>/dev/tcp/localhost/{self.port} && {self.request()} && " + "cat <&3 | grep -q 'HTTP/1'" + ), + ] + + +class HttpStatus(Tcp): + """Like :class:`Tcp`, but insists the status line is 2xx or 3xx.""" + + flavor = "http_status" + + def test(self) -> list[str]: + return [ + "CMD", + "bash", + "-c", + ( + f"exec 3<>/dev/tcp/localhost/{self.port} && {self.request()} && " + "head -n1 <&3 | grep -qE '^HTTP/1\\.[01] [23][0-9][0-9]'" + ), + ] + + +class Nc(Probe): + flavor = "nc" + timeout = "3s" + start_period = "10s" + + def test(self) -> list[str]: + return ["CMD-SHELL", f"nc -z localhost {self.port} || exit 1"] + + +class MsmtpCurl(Probe): + """Probes http, and on the first run also sends one test mail. + + The /tmp/email_sent marker keeps a repeating probe from tripping SMTP + rate limits, and a disabled email provider drops the mail branch so an + unrelated SMTP outage cannot flap the container into unhealthy. + """ + + flavor = "msmtp_curl" + timeout = "20s" + retries = 5 + start_period = "120s" + + def test(self) -> list[str]: + mail = "" + if self.context.get("email_enabled"): + domain = self.context.get("domain", "") + blackhole = self.context.get("blackhole", "") + mail = ( + "if [ ! -f /tmp/email_sent ]; then " + f"echo 'Subject: testmessage from {domain}\\n\\nSUCCESSFULL' " + f"| msmtp -t {blackhole} && touch /tmp/email_sent; fi && " + ) + return ["CMD-SHELL", f"{mail}curl -f {self.url} || exit 1"] + + +PROBES: dict[str, type[Probe]] = { + probe.flavor: probe for probe in (Curl, Wget, Http, Tcp, HttpStatus, Nc, MsmtpCurl) +} + + +def known_flavors() -> str: + return ", ".join(sorted(PROBES)) + + +def build(flavor: str, overrides: dict[str, Any], **context: Any) -> str: + """Render a service's healthcheck block as YAML, starting at column zero. + + Args: + flavor: key into PROBES, or empty to use an explicit ``test`` argv. + overrides: the service's healthcheck entry from services.yml. + context: port, path, hostname, samples and any flavor specific extras. + + Raises: + KeyError: the flavor is unknown. + """ + probe = (PROBES[flavor] if flavor else Custom)(**context) + return dump_yaml_str({"healthcheck": probe.block(overrides)}, width=10**6).rstrip( + "\n" + )