Skip to content

Commit b3a2a4e

Browse files
MCLOUD-5752: Healthchecks for nginx and php fpm (#188)
1 parent 64609c3 commit b3a2a4e

File tree

19 files changed

+112
-5
lines changed

19 files changed

+112
-5
lines changed

images/nginx/1.9/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ COPY etc/nginx.conf /etc/nginx/
1313
COPY etc/vhost.conf /etc/nginx/conf.d/default.conf
1414
COPY etc/xdebug-upstream.conf /etc/nginx/conf.d/xdebug/upstream.conf
1515

16-
RUN apt-get update && apt-get install -y openssl
16+
RUN apt-get update && apt-get install -y openssl curl
1717
RUN mkdir /etc/nginx/ssl \
1818
&& echo -e "\n\n\n\n\n\n\n" | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/magento.key -out /etc/nginx/ssl/magento.crt
1919

2020
RUN groupadd -g 1000 www && useradd -g 1000 -u 1000 -d ${MAGENTO_ROOT} -s /bin/bash www
2121

2222
VOLUME ${MAGENTO_ROOT}
2323

24+
COPY nginx-healthcheck.sh /usr/local/bin/nginx-healthcheck.sh
25+
RUN ["chmod", "+x", "/usr/local/bin/nginx-healthcheck.sh"]
26+
27+
HEALTHCHECK --retries=3 CMD ["bash", "/usr/local/bin/nginx-healthcheck.sh"]
28+
2429
COPY docker-entrypoint.sh /docker-entrypoint.sh
2530
RUN ["chmod", "+x", "/docker-entrypoint.sh"]
2631
ENTRYPOINT ["/docker-entrypoint.sh"]

images/nginx/1.9/etc/vhost.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,16 @@ server {
190190
location ~* (\.php$|\.htaccess$|\.git) {
191191
deny all;
192192
}
193+
194+
location /nginx_status {
195+
stub_status on;
196+
access_log off;
197+
}
198+
199+
location ~ ^/(status|ping)$ {
200+
fastcgi_index index.php;
201+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
202+
include fastcgi_params;
203+
fastcgi_pass $my_fastcgi_pass;
204+
}
193205
}

images/nginx/1.9/nginx-healthcheck.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
nginx_response=$(curl -o /dev/null -s -w "%{http_code}\n" http://${WEB_HOST:-web}:${WEB_PORT:-80}/nginx_status)
6+
7+
if [ "$nginx_response" == "200" ]
8+
then
9+
exit 0
10+
else
11+
echo "The health of the nginx server is not good"
12+
exit 1
13+
fi
14+

images/php/7.1-fpm/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ COPY etc/php-pcov.ini /usr/local/etc/php/conf.d/zz-pcov-settings.ini
172172
COPY etc/mail.ini /usr/local/etc/php/conf.d/zz-mail.ini
173173
COPY etc/php-fpm.conf /usr/local/etc/
174174

175+
COPY fpm-healthcheck.sh /usr/local/bin/fpm-healthcheck.sh
176+
RUN ["chmod", "+x", "/usr/local/bin/fpm-healthcheck.sh"]
177+
178+
HEALTHCHECK --retries=3 CMD ["bash", "/usr/local/bin/fpm-healthcheck.sh"]
179+
175180
COPY docker-entrypoint.sh /docker-entrypoint.sh
176181
RUN ["chmod", "+x", "/docker-entrypoint.sh"]
177182

images/php/7.1-fpm/etc/php-fpm.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pm.max_children = 10
1515
pm.start_servers = 4
1616
pm.min_spare_servers = 2
1717
pm.max_spare_servers = 6
18+
pm.status_path = /status
1819

1920
env[MAGE_MODE] = !MAGENTO_RUN_MODE!; # Variable: MAGENTO_RUN_MODE
2021

images/php/7.1-fpm/fpm-healthcheck.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
fpm_response=$(curl -o /dev/null -s -w "%{http_code}\n" http://${WEB_HOST:-web}:${WEB_PORT:-80}/status)
5+
6+
if [ "$fpm_response" == "200" ]
7+
then
8+
exit 0
9+
else
10+
echo "The health of the FPM server is not good"
11+
exit 1
12+
fi
13+

images/php/7.2-fpm/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ COPY etc/php-pcov.ini /usr/local/etc/php/conf.d/zz-pcov-settings.ini
172172
COPY etc/mail.ini /usr/local/etc/php/conf.d/zz-mail.ini
173173
COPY etc/php-fpm.conf /usr/local/etc/
174174

175+
COPY fpm-healthcheck.sh /usr/local/bin/fpm-healthcheck.sh
176+
RUN ["chmod", "+x", "/usr/local/bin/fpm-healthcheck.sh"]
177+
178+
HEALTHCHECK --retries=3 CMD ["bash", "/usr/local/bin/fpm-healthcheck.sh"]
179+
175180
COPY docker-entrypoint.sh /docker-entrypoint.sh
176181
RUN ["chmod", "+x", "/docker-entrypoint.sh"]
177182

images/php/7.2-fpm/etc/php-fpm.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pm.max_children = 10
1515
pm.start_servers = 4
1616
pm.min_spare_servers = 2
1717
pm.max_spare_servers = 6
18+
pm.status_path = /status
1819

1920
env[MAGE_MODE] = !MAGENTO_RUN_MODE!; # Variable: MAGENTO_RUN_MODE
2021

images/php/7.2-fpm/fpm-healthcheck.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
fpm_response=$(curl -o /dev/null -s -w "%{http_code}\n" http://${WEB_HOST:-web}:${WEB_PORT:-80}/status)
5+
6+
if [ "$fpm_response" == "200" ]
7+
then
8+
exit 0
9+
else
10+
echo "The health of the FPM server is not good"
11+
exit 1
12+
fi
13+

images/php/7.3-fpm/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ COPY etc/php-pcov.ini /usr/local/etc/php/conf.d/zz-pcov-settings.ini
168168
COPY etc/mail.ini /usr/local/etc/php/conf.d/zz-mail.ini
169169
COPY etc/php-fpm.conf /usr/local/etc/
170170

171+
COPY fpm-healthcheck.sh /usr/local/bin/fpm-healthcheck.sh
172+
RUN ["chmod", "+x", "/usr/local/bin/fpm-healthcheck.sh"]
173+
174+
HEALTHCHECK --retries=3 CMD ["bash", "/usr/local/bin/fpm-healthcheck.sh"]
175+
171176
COPY docker-entrypoint.sh /docker-entrypoint.sh
172177
RUN ["chmod", "+x", "/docker-entrypoint.sh"]
173178

0 commit comments

Comments
 (0)