Skip to content

Commit

Permalink
Make nginx readiness endpoint dependant on a working socket to fpm
Browse files Browse the repository at this point in the history
  • Loading branch information
EarthlingDavey committed Oct 30, 2024
1 parent a39c978 commit 49be7fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion deploy/config/local/nginx/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}
1 change: 1 addition & 0 deletions public/metrics/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function serveMetrics(): void
{
header('Content-Type', 'text/plain');
echo $this->getServiceMetrics();
unset($this->guzzle_client);
exit();
}
}
Expand Down
3 changes: 3 additions & 0 deletions public/metrics/socket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo 'OK';

0 comments on commit 49be7fa

Please sign in to comment.