File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed
Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change 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+ # 9 - 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
Original file line number Diff line number Diff line change 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 .alpine
20+ def test_exit_when_fpm_is_not_reachable_apk (host ):
21+ cmd = host .run ("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v" )
22+ assert cmd .rc == 9
23+ assert "Trying to connect to php-fpm via: localhost:9001" in cmd .stdout
24+
25+ @pytest .mark .alpine
26+ def test_exit_when_fpm_is_invalid_host_apk (host ):
27+ cmd = host .run ("FCGI_CONNECT=abc php-fpm-healthcheck -v" )
28+ assert cmd .rc == 9
29+ assert "Trying to connect to php-fpm via: abc" in cmd .stdout
30+
31+ @pytest .mark .stretch
32+ def test_exit_when_fpm_is_not_reachable_apt (host ):
33+ cmd = host .run ("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v" )
34+ assert cmd .rc == 111
35+ assert "Trying to connect to php-fpm via: localhost:9001" in cmd .stdout
36+
37+ @pytest .mark .stretch
38+ def test_exit_when_fpm_is_invalid_host_apt (host ):
39+ cmd = host .run ("FCGI_CONNECT=abc php-fpm-healthcheck -v" )
40+ assert cmd .rc == 2
41+ assert "Trying to connect to php-fpm via: abc" in cmd .stdout
You can’t perform that action at this time.
0 commit comments