Skip to content

Commit 008eb1a

Browse files
authored
Merge pull request #32 from renatomefi/feature/configurable-status-path
Allow to configure FPM healthcheck status page path
2 parents 9d3510e + 4101ab6 commit 008eb1a

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Or with `verbose` to see php-fpm status output:
8383

8484
```console
8585
$ php-fpm-healthcheck -v
86-
Trying to connect to php-fpm via: localhost:9000
86+
Trying to connect to php-fpm via: localhost:9000/status
8787
php-fpm status output:
8888
pool: www
8989
process manager: dynamic
@@ -140,6 +140,21 @@ $ echo $?
140140
0
141141
```
142142

143+
### Alternative status page path
144+
145+
_Since v0.5.0_
146+
147+
While the default status page path is `/status`, you can replace it in your php-fpm configuration, in order to change
148+
also in the script in you can specify `FCGI_STATUS_PATH` env var within your connection uri:
149+
150+
```console
151+
$ FCGI_STATUS_PATH=/custom-status-path php-fpm-healthcheck -v
152+
Trying to connect to php-fpm via: localhost:9000/custom-status-path
153+
...
154+
$ echo $?
155+
0
156+
```
157+
143158
## Kubernetes example
144159

145160
More and more people are looking for health checks on kubernetes for php-fpm, here is an example of livenessProbe and readinessProbe:

php-fpm-healthcheck

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ set -eu
4343

4444
OPTIND=1 # Reset getopt in case it has been used previously in the shell
4545

46-
# FastCGI variables
47-
export REQUEST_METHOD="GET"
48-
export SCRIPT_NAME="/status"
49-
export SCRIPT_FILENAME="/status"
50-
FCGI_CONNECT_DEFAULT="localhost:9000"
51-
5246
# Required software
5347
FCGI_CMD_PATH=$(command -v cgi-fcgi) || { >&2 echo "Make sure fcgi is installed (i.e. apk add --no-cache fcgi). Aborting."; exit 4; }
5448
command -v sed 1> /dev/null || { >&2 echo "Make sure sed is installed (i.e. apk add --no-cache busybox). Aborting."; exit 4; }
@@ -58,7 +52,7 @@ command -v grep 1> /dev/null || { >&2 echo "Make sure grep is installed (i.e. ap
5852
# Get status from fastcgi connection
5953
# $1 - cgi-fcgi connect argument
6054
get_fpm_status() {
61-
if test "$VERBOSE" = 1; then printf "Trying to connect to php-fpm via: %s\\n" "$1"; fi;
55+
if test "$VERBOSE" = 1; then printf "Trying to connect to php-fpm via: %s%s\\n" "$1" "$SCRIPT_NAME"; fi;
6256

6357
# Since I cannot use pipefail I'll just split these in two commands
6458
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)
@@ -120,6 +114,13 @@ fi;
120114

121115
eval set -- "$GETOPT"
122116

117+
# FastCGI variables
118+
FCGI_CONNECT_DEFAULT="localhost:9000"
119+
FCGI_STATUS_PATH_DEFAULT="/status"
120+
121+
export REQUEST_METHOD="GET"
122+
export SCRIPT_NAME="${FCGI_STATUS_PATH:-$FCGI_STATUS_PATH_DEFAULT}"
123+
export SCRIPT_FILENAME="${FCGI_STATUS_PATH:-$FCGI_STATUS_PATH_DEFAULT}"
123124
FCGI_CONNECT="${FCGI_CONNECT:-$FCGI_CONNECT_DEFAULT}"
124125

125126
VERBOSE=0

test/docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -eEuo pipefail
1111
function cleanup {
1212
docker stop "$CONTAINER" 1> /dev/null
1313
echo "container $CONTAINER: stopped"
14-
docker rmi -f "$DOCKER_TAG_TEMPORARY"
14+
docker rmi -f "$DOCKER_TAG_TEMPORARY"
1515
}
1616
trap cleanup EXIT
1717

test/testinfra/test_execution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def test_valid_with_non_integer_value_exits_properly(host):
2222

2323
@pytest.mark.php_fpm
2424
def test_all_available_options_at_once(host):
25-
cmd = host.run("php-fpm-healthcheck --accepted-conn=1000 --listen-queue=1000 --max-listen-queue=1000 --listen-queue-len=1000 --idle-processes=1000 --active-processes=1000 --total-processes=1000 --max-active-processes=1000 --max-children-reached=1000 --slow-requests=1000")
25+
cmd = host.run("php-fpm-healthcheck --accepted-conn=1000 --listen-queue=1000 --max-listen-queue=1000 "
26+
"--listen-queue-len=1000 --idle-processes=1000 --active-processes=1000 --total-processes=1000 "
27+
"--max-active-processes=1000 --max-children-reached=1000 --slow-requests=1000")
2628
assert cmd.rc == 0
2729

2830
@pytest.mark.php_fpm

test/testinfra/test_fpm.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ def test_fpm_on_socket_with_huge_env(host, setup_fpm_to_default_fixture):
4747
assert "status output:" in cmd.stdout
4848
assert "pool:" in cmd.stdout
4949

50+
@pytest.mark.php_fpm
51+
def test_default_status_page_path(host, setup_fpm_to_default_fixture):
52+
cmd = host.run("php-fpm-healthcheck -v")
53+
assert cmd.rc == 0
54+
assert "Trying to connect to php-fpm via: localhost:9000/status" in cmd.stdout
55+
56+
@pytest.mark.php_fpm
57+
def test_exit_when_fpm_is_invalid_path(host, setup_fpm_to_default_fixture):
58+
cmd = host.run("FCGI_STATUS_PATH=/invalid php-fpm-healthcheck -v")
59+
assert cmd.rc == 8
60+
assert "Trying to connect to php-fpm via: localhost:9000/invalid" in cmd.stdout
61+
assert "File not found." in cmd.stdout
62+
assert "php-fpm status page non reachable" in cmd.stderr
63+
5064
@pytest.mark.alpine
5165
def test_exit_when_fpm_is_not_reachable_apk(host, setup_fpm_to_default_fixture):
5266
cmd = host.run("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v")
@@ -70,3 +84,4 @@ def test_exit_when_fpm_is_invalid_host_apt(host, setup_fpm_to_default_fixture):
7084
cmd = host.run("FCGI_CONNECT=abc php-fpm-healthcheck -v")
7185
assert cmd.rc == 2
7286
assert "Trying to connect to php-fpm via: abc" in cmd.stdout
87+

0 commit comments

Comments
 (0)