[containers] Add healthcheck for SSO redirections

This will help us catch issues in e.g. moodle, nextcloud and wp.
mejoras_instalacion
Evilham 2022-09-21 17:51:35 +02:00
parent 397655232f
commit 7d7c2ddfcf
No known key found for this signature in database
GPG Key ID: AE3EE30D970886BF
6 changed files with 54 additions and 2 deletions

View File

@ -8,6 +8,7 @@ COPY src/rootfs/ /
COPY 02-configure-moodle.sh /docker-entrypoint-init.d/ COPY 02-configure-moodle.sh /docker-entrypoint-init.d/
COPY 03-plugins.sh /docker-entrypoint-init.d/ COPY 03-plugins.sh /docker-entrypoint-init.d/
COPY src/rootfs/var/www/html/admin/cli/isinstalled.php / COPY src/rootfs/var/www/html/admin/cli/isinstalled.php /
COPY is_moodle_ready.sh /
RUN echo "user=nobody" >> /etc/php7/php-fpm.d/www.conf RUN echo "user=nobody" >> /etc/php7/php-fpm.d/www.conf
RUN echo "group=nobody" >> /etc/php7/php-fpm.d/www.conf RUN echo "group=nobody" >> /etc/php7/php-fpm.d/www.conf
RUN apk add --no-cache dcron libcap && \ RUN apk add --no-cache dcron libcap && \

View File

@ -0,0 +1,12 @@
#!/bin/sh -eu
# Check exclusively whether moodle has been installed and the web service is up
if test -f /var/www/html/admin/cli/isinstalled.php && \
! php -d max_input_vars=$max_input_vars \
/var/www/html/admin/cli/isinstalled.php 2>&1 > /dev/null && \
curl -s --output /dev/null localhost:8080; then
exit 0
else
# Force exit status 1, docker reserves exit status 2
exit 1
fi

View File

@ -47,5 +47,14 @@ services:
- max_input_vars=5000 - max_input_vars=5000
- max_execution_time=${MOODLE_MAX_EXECUTION_TIME} - max_execution_time=${MOODLE_MAX_EXECUTION_TIME}
- memory_limit=${MOODLE_MEMORY_LIMIT} - memory_limit=${MOODLE_MEMORY_LIMIT}
healthcheck:
test: |
curl -L --max-redirs 1 \
--proxy-basic 'http://localhost:8080' \
-sw '%{redirect_url}' \
'http://moodle.${DOMAIN}/' | grep -q 'https://sso.${DOMAIN}'
interval: 30s
timeout: 10s
retries: 5
networks: networks:
- dd_net - dd_net

View File

@ -56,5 +56,14 @@ services:
volumes: volumes:
- ${BUILD_APPS_ROOT_PATH}/docker/nextcloud/nginx.conf:/etc/nginx/nginx.conf:ro - ${BUILD_APPS_ROOT_PATH}/docker/nextcloud/nginx.conf:/etc/nginx/nginx.conf:ro
- ${SRC_FOLDER}/nextcloud:/var/www/html:ro - ${SRC_FOLDER}/nextcloud:/var/www/html:ro
healthcheck:
test: |
curl -L --max-redirs 1 \
--proxy-basic 'http://localhost:8080' \
-sw '%{redirect_url}' \
'https://nextcloud.${DOMAIN}/login' | grep -q 'https://sso.${DOMAIN}'
interval: 30s
timeout: 10s
retries: 5
networks: networks:
- dd_net - dd_net

View File

@ -47,7 +47,11 @@ services:
- dd-apps-mariadb - dd-apps-mariadb
restart: unless-stopped restart: unless-stopped
healthcheck: healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80"] test: |
curl \
--proxy-basic 'http://localhost' \
-sw '%{redirect_url}' \
'https://wp.${DOMAIN}/' | grep -q 'https://sso.${DOMAIN}'
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 5 retries: 5

19
dd-ctl
View File

@ -500,7 +500,14 @@ saml_certificates(){
wait_for_moodle(){ wait_for_moodle(){
echo "Waiting for system to be fully up before customizing... It can take some minutes..." echo "Waiting for system to be fully up before customizing... It can take some minutes..."
echo " (you can monitorize install with: docker logs dd-apps-moodle --follow" echo " (you can monitorize install with: docker logs dd-apps-moodle --follow"
while ! docker inspect -f '{{.State.Health.Status}}' dd-apps-moodle | grep -q "^healthy$"; do sleep 2; done # This previously waited for the container to be 'healthy',
# but that was not what is actually required here, which is:
# - Is moodle installed?
# - Is the web service up?
# That is now checked in /is_moodle_ready.sh
while ! docker exec dd-apps-moodle /is_moodle_ready.sh; do
sleep 2;
done
} }
upgrade_moodle(){ upgrade_moodle(){
@ -865,6 +872,16 @@ case "$OPERATION" in
listpatches) listpatches)
listpatches listpatches
;; ;;
failing-containers)
fc="$(docker ps --format '{{.Names}}' -f 'health=unhealthy')"
if [ -n "${fc}" ]; then
cat >&2 <<-EOF
Failing containers:
${fc}
EOF
exit 1
fi
;;
genpatches) genpatches)
genpatches genpatches
;; ;;