Skip to content

Commit 953ca22

Browse files
author
Gabriel Fernandes
committed
Use cgi response code as error check point
1 parent 6b560ef commit 953ca22

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

php-fpm-healthcheck

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ command -v grep 1> /dev/null || { >&2 echo "Make sure grep is installed (i.e. ap
5454
get_fpm_status() {
5555
if test "$VERBOSE" = 1; then printf "Trying to connect to php-fpm via: %s%s\\n" "$1" "$SCRIPT_NAME"; fi;
5656

57-
# Since I cannot use pipefail I'll just split these in two commands
5857
FPM_STATUS=$(env -i REQUEST_METHOD="$REQUEST_METHOD" SCRIPT_NAME="$SCRIPT_NAME" SCRIPT_FILENAME="$SCRIPT_FILENAME" "$FCGI_CMD_PATH" -bind -connect "$1" 2> /dev/null)
58+
RESPONSE_CODE=$(echo "$FPM_STATUS" | grep -o -E "^Status:\s*\d{3}" | sed 's/[^0-9]*//g')
5959
FPM_STATUS=$(echo "$FPM_STATUS" | tail +5)
6060

6161
if test "$VERBOSE" = 1; then printf "php-fpm status output:\\n%s\\n" "$FPM_STATUS"; fi;
6262

63-
if test "$FPM_STATUS" = "File not found."; then
63+
if ! test "$RESPONSE_CODE" -eq "$RESPONSE_CODE" 2> /dev/null; then
64+
return
65+
fi
66+
67+
if test "$RESPONSE_CODE" -lt 200 -o "$RESPONSE_CODE" -ge 400; then
6468
>&2 printf "php-fpm status page non reachable\\n";
6569
exit 8;
6670
fi;

0 commit comments

Comments
 (0)