Skip to content

Commit c760908

Browse files
authored
Merge pull request #13 from renatomefi/improvement/report-fpm-no-status-page
Report fpm no status page
2 parents 7e35462 + 972097f commit c760908

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

php-fpm-healthcheck

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
# Ping mode with data (outputs php-fpm status text): ./php-fpm-healthcheck -v
1919
#
2020
# Exit status codes:
21-
# 9 - Couldn't reach PHP fpm status page, have you configured it with `pm.status_path = /status`?
21+
# 2,9,111 - Couldn't connect to PHP fpm, is it running?
22+
# 8 - Couldn't reach PHP fpm status page, have you configured it with `pm.status_path = /status`?
2223
# 1 - A healthcheck condition has failed
2324
# 3 - Invalid option given
2425
# 4 - One or more required softwares are missing
@@ -55,10 +56,15 @@ get_fpm_status() {
5556
if test "$VERBOSE" = 1; then printf "Trying to connect to php-fpm via: %s\\n" "$1"; fi;
5657

5758
# Since I cannot use pipefail I'll just split these in two commands
58-
FPM_STATUS=$(cgi-fcgi -bind -connect "$1")
59+
FPM_STATUS=$(cgi-fcgi -bind -connect "$1" 2> /dev/null)
5960
FPM_STATUS=$(echo "$FPM_STATUS" | tail +5)
6061

6162
if test "$VERBOSE" = 1; then printf "php-fpm status output:\\n%s\\n" "$FPM_STATUS"; fi;
63+
64+
if test "$FPM_STATUS" = "File not found."; then
65+
>&2 printf "php-fpm status page non reachable\\n";
66+
exit 8;
67+
fi;
6268
}
6369

6470
# $1 - fpm option

test/docker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Author: <Renato Mefi [email protected]> https://github.com/renatomefi
44
#
55
# This script is suppose to be ran via Makefile, i.e.:
6-
# $ make test-image IMAGE="php:7.2-fpm-alpine3.7"
6+
# $ make test-image DOCKERFILE="alpine" IMAGE="php:7.2-fpm-alpine3.7"
7+
# $ make test-image DOCKERFILE="stretch" IMAGE="php:7.2-fpm-stretch"
78

89
set -eEuo pipefail
910

test/testinfra/test_fpm.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pytest
2+
3+
@pytest.mark.php_fpm
4+
def test_exit_when_no_status_page_is_configured(host):
5+
# disable fpm status page
6+
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/pm.status_path/ s/^;*/;/'")
7+
host.run("kill -USR2 1")
8+
9+
cmd = host.run("php-fpm-healthcheck -v")
10+
assert cmd.rc == 8
11+
assert "Trying to connect to php-fpm via:" in cmd.stdout
12+
assert "status output:" in cmd.stdout
13+
assert "php-fpm status page non reachable" in cmd.stderr
14+
15+
# enable fpm status page back
16+
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/;pm.status_path/ s/^;*//'")
17+
host.run("kill -USR2 1")
18+
19+
@pytest.mark.php_fpm
20+
def test_fpm_on_socket(host):
21+
# change fpm to socket
22+
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/^listen/ s/.*/listen = \\/var\\/run\\/php-fpm.sock/'")
23+
host.run("kill -USR2 1")
24+
25+
cmd = host.run("FCGI_CONNECT=/var/run/php-fpm.sock php-fpm-healthcheck -v")
26+
assert cmd.rc == 0
27+
assert "Trying to connect to php-fpm via:" in cmd.stdout
28+
assert "status output:" in cmd.stdout
29+
assert "pool:" in cmd.stdout
30+
31+
# change fpm back to port 9000
32+
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/^listen/ s/.*/listen = 9000/'")
33+
host.run("kill -USR2 1")
34+
35+
@pytest.mark.alpine
36+
def test_exit_when_fpm_is_not_reachable_apk(host):
37+
cmd = host.run("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v")
38+
assert cmd.rc == 9
39+
assert "Trying to connect to php-fpm via: localhost:9001" in cmd.stdout
40+
41+
@pytest.mark.alpine
42+
def test_exit_when_fpm_is_invalid_host_apk(host):
43+
cmd = host.run("FCGI_CONNECT=abc php-fpm-healthcheck -v")
44+
assert cmd.rc == 9
45+
assert "Trying to connect to php-fpm via: abc" in cmd.stdout
46+
47+
@pytest.mark.stretch
48+
def test_exit_when_fpm_is_not_reachable_apt(host):
49+
cmd = host.run("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v")
50+
assert cmd.rc == 111
51+
assert "Trying to connect to php-fpm via: localhost:9001" in cmd.stdout
52+
53+
@pytest.mark.stretch
54+
def test_exit_when_fpm_is_invalid_host_apt(host):
55+
cmd = host.run("FCGI_CONNECT=abc php-fpm-healthcheck -v")
56+
assert cmd.rc == 2
57+
assert "Trying to connect to php-fpm via: abc" in cmd.stdout

0 commit comments

Comments
 (0)