From 49be7fac294e9dc6b0a6f7031a2da581ebbd2d4f Mon Sep 17 00:00:00 2001 From: EarthlingDavey <15802017+EarthlingDavey@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:37:17 +0000 Subject: [PATCH] Make nginx readiness endpoint dependant on a working socket to fpm --- deploy/config/local/nginx/server.conf | 17 ++++++++++++++++- public/metrics/service.php | 1 + public/metrics/socket.php | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 public/metrics/socket.php diff --git a/deploy/config/local/nginx/server.conf b/deploy/config/local/nginx/server.conf index be1c5c58f..8d0076ceb 100644 --- a/deploy/config/local/nginx/server.conf +++ b/deploy/config/local/nginx/server.conf @@ -116,6 +116,11 @@ server { set $skip_cache 1; } + # ...it's to the readiness endpoint + if ($request_uri = "/readiness") { + set $skip_cache 1; + } + # ...it's from a logged in user, the cookie 'wordpress_no_cache' exists. if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; @@ -303,8 +308,18 @@ server { # LOCATIONS - heath ## - location ~ ^/(liveness|readiness)$ { + location = /liveness { return 200; } + location = /readiness { + # Make sure we can connect to php-fpm via the socket. + set $script_name /metrics/socket.php; + + fastcgi_param SCRIPT_FILENAME $document_root$script_name; + include fastcgi_params; + + fastcgi_pass fpm; + } + } diff --git a/public/metrics/service.php b/public/metrics/service.php index 8b81d26ef..c352d9bf3 100644 --- a/public/metrics/service.php +++ b/public/metrics/service.php @@ -140,6 +140,7 @@ public function serveMetrics(): void { header('Content-Type', 'text/plain'); echo $this->getServiceMetrics(); + unset($this->guzzle_client); exit(); } } diff --git a/public/metrics/socket.php b/public/metrics/socket.php new file mode 100644 index 000000000..1abc618f2 --- /dev/null +++ b/public/metrics/socket.php @@ -0,0 +1,3 @@ +