Skip to content

Commit

Permalink
Liveness probe for apache, cgimap and postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
Rub21 committed Oct 25, 2024
1 parent e395e56 commit b43b2cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
41 changes: 34 additions & 7 deletions images/web/liveness.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 1 addition & 17 deletions osm-seed/templates/web/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b43b2cb

Please sign in to comment.