diff --git a/Dockerfile b/Dockerfile index c06417ecba..c26c4462c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,7 +83,7 @@ COPY ./deploy/docker/templates/supervisord/ templates/supervisord/ COPY ./deploy/docker/templates/cron.d /etc/cron.d/ RUN chmod 0644 /etc/cron.d/* -RUN chmod +x entrypoint.sh renew-certificate.sh +RUN chmod +x entrypoint.sh renew-certificate.sh healthcheck.sh # Disable setuid/setgid bits for the files inside container. RUN find / \( -path /proc -prune \) -o \( \( -perm -2000 -o -perm -4000 \) -print -exec chmod -s '{}' + \) || true @@ -94,4 +94,5 @@ ENV PATH /opt/appsmith/utils/node_modules/.bin:$PATH EXPOSE 80 EXPOSE 443 ENTRYPOINT [ "/opt/appsmith/entrypoint.sh" ] +HEALTHCHECK --interval=15s --timeout=15s --start-period=45s CMD "/opt/appsmith/healthcheck.sh" CMD ["/usr/bin/supervisord", "-n"] diff --git a/app/client/Dockerfile b/app/client/Dockerfile index aaf1006e6a..7c0e932de1 100644 --- a/app/client/Dockerfile +++ b/app/client/Dockerfile @@ -16,4 +16,5 @@ COPY ./docker/templates/nginx-app-https.conf.template /nginx-app-https.conf.temp # This is the script that is used to start Nginx when the Docker container starts COPY ./docker/start-nginx.sh /start-nginx.sh +HEALTHCHECK --interval=15s --timeout=15s --start-period=15s --retries=3 CMD curl -f http://localhost:80/ || exit 1 CMD ["/start-nginx.sh"] diff --git a/app/server/Dockerfile b/app/server/Dockerfile index 5d8e911e72..c3a9382073 100644 --- a/app/server/Dockerfile +++ b/app/server/Dockerfile @@ -30,5 +30,5 @@ RUN chmod +x /entrypoint.sh #care of via the cache happens. The following statement would lead to copy because of change in hash value COPY ${JAR_FILE} server.jar COPY ${PLUGIN_JARS} /plugins/ - +HEALTHCHECK --interval=15s --timeout=15s --start-period=15s --retries=3 CMD wget --no-verbose --spider http://localhost:8080/api/v1/users/me/ || exit 1 ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/deploy/docker/scripts/healthcheck.sh b/deploy/docker/scripts/healthcheck.sh new file mode 100644 index 0000000000..2678b8458e --- /dev/null +++ b/deploy/docker/scripts/healthcheck.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +healthy=true +while read -r line + do + line_arr=($line) + process=${line_arr[0]} + status=${line_arr[1]} + if [ $status != "RUNNING" ]; then + healthy=false + echo "ERROR:- PROCESS: $process - STATUS: $status" + else + echo "PROCESS: $process - STATUS: $status" + if [[ "$process" == 'editor' ]]; then + if [[ $(curl -s -w "%{http_code}\n" http://localhost:80/ -o /dev/null) -ne 200 ]]; then + echo 'ERROR: Editor is down'; + healthy=false + fi + elif [[ "$process" == "server" ]]; then + if [[ $(curl -s -w "%{http_code}\n" http://localhost:8080/api/v1/users/me/ -o /dev/null) -ne 200 ]]; then + echo 'ERROR: Server is down'; + healthy=false + fi + elif [[ "$process" == "rts" ]]; then + if [[ $(curl -s -w "%{http_code}\n" http://localhost:8091/ -o /dev/null) -ne 302 ]]; then + echo 'ERROR: RTS is down'; + healthy=false + fi + elif [[ "$process" == "mongo" ]]; then + if [[ $(mongo --eval 'db.runCommand("ping").ok') -ne 1 ]]; then + echo 'ERROR: Mongo is down'; + healthy=false + fi + elif [[ "$process" == "redis" ]]; then + if [[ $(redis-cli ping) != 'PONG' ]]; then + echo 'ERROR: Redis is down'; + healthy=false + fi + fi + fi + done <<< $(supervisorctl status all) +if [ $healthy == true ]; then + exit 0 +else + exit 1 +fi \ No newline at end of file