From b43b2cb2686b124dfa415a2424adef354181b8e5 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Fri, 25 Oct 2024 10:18:04 -0500 Subject: [PATCH] Liveness probe for apache, cgimap and postgres --- images/web/liveness.sh | 41 ++++++++++++++++++---- osm-seed/templates/web/web-deployment.yaml | 18 +--------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/images/web/liveness.sh b/images/web/liveness.sh index 5d30dfd1..331df5b9 100755 --- a/images/web/liveness.sh +++ b/images/web/liveness.sh @@ -1,9 +1,36 @@ #!/usr/bin/env bash -# This is a script for the complex evaluation of whether Apache or other processes are running in the container. -if [ $(ps -ef | grep -E 'httpd|apache2' | grep -v grep | wc -l) -ge 1 ]; then - echo "Apache is running." - exit 0 +# This is a script for evaluating if openstreetmap-cgimap, apache2, and PostgreSQL are running in the container. +check_process() { + if ps aux | grep "$1" | grep -v grep > /dev/null; then + return 0 + else + return 1 + fi +} + +# Check for openstreetmap-cgimap process +check_process "/openstreetmap-cgimap/build/openstreetmap-cgimap" +cgimap_status=$? + +# Check for apache2 process +check_process "apache2" +apache_status=$? + +# Check PostgreSQL connection +check_postgres() { + PGPASSWORD=$POSTGRES_PASSWORD psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DB -c "SELECT 1;" > /dev/null 2>&1 + return $? +} + +check_postgres +postgres_status=$? + +if [ $cgimap_status -eq 0 ] && [ $apache_status -eq 0 ] && [ $postgres_status -eq 0 ]; then + echo "All services (openstreetmap-cgimap, apache2, PostgreSQL) are running." + exit 0 else - echo "Apache is not running!" 1>&2 - exit 1 -fi + [ $cgimap_status -ne 0 ] && echo "openstreetmap-cgimap is not running!" 1>&2 + [ $apache_status -ne 0 ] && echo "apache2 is not running!" 1>&2 + [ $postgres_status -ne 0 ] && echo "Failed to connect to PostgreSQL!" 1>&2 + exit 1 +fi \ No newline at end of file diff --git a/osm-seed/templates/web/web-deployment.yaml b/osm-seed/templates/web/web-deployment.yaml index 22641b66..22f0cf98 100644 --- a/osm-seed/templates/web/web-deployment.yaml +++ b/osm-seed/templates/web/web-deployment.yaml @@ -35,23 +35,7 @@ spec: command: - /bin/bash - -c - - > - # Check PostgreSQL connection - PGPASSWORD=$POSTGRES_PASSWORD psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DB -c "SELECT 1;" > /dev/null 2>&1; - if [ $? -ne 0 ]; then - echo "Failed to connect to PostgreSQL"; - exit 1; - fi; - - # Check apache status - ./liveness.sh; - if [ $? -ne 0 ]; then - echo "liveness.sh script failed"; - exit 1; - fi; - - echo "All checks passed"; - exit 0; + - ./liveness.sh initialDelaySeconds: 600 timeoutSeconds: 5 periodSeconds: 10