-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Liveness probe for apache, cgimap and postgres
- Loading branch information
Showing
2 changed files
with
35 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters