Skip to content

Commit

Permalink
Merge fb97ed7 into 9d5c55b
Browse files Browse the repository at this point in the history
  • Loading branch information
gronka committed Apr 17, 2024
2 parents 9d5c55b + fb97ed7 commit 525a9e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Dockerfile
Expand Up @@ -207,6 +207,7 @@ EXPOSE 80
###############*
ADD docker/salt/ /srv/salt/
ADD docker/run.sh ${TETHYS_HOME}/
ADD docker/liveness-probe.sh ${TETHYS_HOME}/

########
# RUN! #
Expand All @@ -215,7 +216,4 @@ WORKDIR ${TETHYS_HOME}
# Create Salt configuration based on ENVs
CMD bash run.sh
HEALTHCHECK --start-period=240s \
CMD function check_process_is_running(){ if [ "$(ps $1 | wc -l)" -ne 2 ]; then echo The $2 process \($1\) is not running. 1>&2; return 1; fi }; \
check_process_is_running $(cat $(grep 'pidfile=.*' /etc/supervisor/supervisord.conf | awk -F'=' '{print $2}' | awk '{print $1}')) supervisor; \
check_process_is_running $(cat $(grep 'pid .*;' /etc/nginx/nginx.conf | awk '{print $2}' | awk -F';' '{print $1}')) nginx; \
check_process_is_running $(ls -l /run/tethys_asgi0.sock.lock | awk -F'-> ' '{print $2}') asgi;
CMD ./liveness-probe.sh
6 changes: 6 additions & 0 deletions docker/docker-compose.yml
Expand Up @@ -13,6 +13,12 @@ services:
TETHYS_DB_SUPERUSER: "tethys_super"
TETHYS_DB_SUPERUSER_PASS: "pass"
CLIENT_MAX_BODY_SIZE: "75M"
healthcheck:
test: ["CMD", "./liveness-probe.sh"]
interval: 30s # docker default
timeout: 30s # docker default
retries: 3 # docker default
start_period: 4m
links:
- db
depends_on:
Expand Down
21 changes: 21 additions & 0 deletions docker/liveness-probe.sh
@@ -0,0 +1,21 @@
#!/bin/sh

check_process_is_running() {
if [ "$(ps $1 | wc -l)" -ne 2 ]; then
echo The $2 process \($1\) is not running. 1>&2;
else
echo "ok"
fi
}

ret1=$(check_process_is_running $(cat $(grep 'pidfile=.*' /etc/supervisor/supervisord.conf | awk -F'=' '{print $2}' | awk '{print $1}')) supervisor)
ret2=$(check_process_is_running $(cat $(grep 'pid .*;' /etc/nginx/nginx.conf | awk '{print $2}' | awk -F';' '{print $1}')) nginx)
ret3=$(check_process_is_running $(ls -l /run/tethys_asgi0.sock.lock | awk -F'-> ' '{print $2}') asgi)

if [ "$ret1" != "ok" ] || [ "$ret2" != "ok" ] || [ "$ret3" != "ok" ]; then
echo "liveness-probe.sh: at least 1 test failed"
exit 1
else
echo "liveness-probe.sh: all tests passed"
exit 0
fi

0 comments on commit 525a9e7

Please sign in to comment.