Add healthcheck to docker (#13154)

This commit is contained in:
Sumesh Pradhan 2022-05-06 11:45:56 +05:30 committed by GitHub
parent f6c753b5e0
commit 5e92d48037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 2 deletions

View File

@ -83,7 +83,7 @@ COPY ./deploy/docker/templates/supervisord/ templates/supervisord/
COPY ./deploy/docker/templates/cron.d /etc/cron.d/ COPY ./deploy/docker/templates/cron.d /etc/cron.d/
RUN chmod 0644 /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. # 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 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 80
EXPOSE 443 EXPOSE 443
ENTRYPOINT [ "/opt/appsmith/entrypoint.sh" ] ENTRYPOINT [ "/opt/appsmith/entrypoint.sh" ]
HEALTHCHECK --interval=15s --timeout=15s --start-period=45s CMD "/opt/appsmith/healthcheck.sh"
CMD ["/usr/bin/supervisord", "-n"] CMD ["/usr/bin/supervisord", "-n"]

View File

@ -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 # This is the script that is used to start Nginx when the Docker container starts
COPY ./docker/start-nginx.sh /start-nginx.sh 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"] CMD ["/start-nginx.sh"]

View File

@ -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 #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 ${JAR_FILE} server.jar
COPY ${PLUGIN_JARS} /plugins/ 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"] ENTRYPOINT ["/entrypoint.sh"]

View File

@ -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