From 540bdf50227400c5c64f7ac7005f45180b84067c Mon Sep 17 00:00:00 2001 From: stremovsky Date: Fri, 17 Dec 2021 09:43:48 +0200 Subject: [PATCH] Add health check to the project --- Dockerfile | 3 ++- health-check.sh | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 health-check.sh diff --git a/Dockerfile b/Dockerfile index 51f646c..84e2faf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,7 +41,8 @@ RUN /bin/busybox mkdir -p /databunker/data && \ # Tell docker that all future commands should run as the appuser user USER appuser COPY --from=builder /go/bin/databunker /databunker/bin/databunker -COPY run.sh /databunker/bin/ +COPY run.sh health-check.sh /databunker/bin/ EXPOSE 3000 +HEALTHCHECK --interval=5s --timeout=3s --start-period=33s --retries=3 CMD /databunker/bin/health-check.sh ENTRYPOINT ["/bin/sh", "/databunker/bin/run.sh"] #CMD ["/bin/sh", "-x", "-c", "/go/bin/databunker -init"] diff --git a/health-check.sh b/health-check.sh new file mode 100755 index 0000000..e06f2fe --- /dev/null +++ b/health-check.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# check if Databunker is using SSL port +if [ -n "$SSL_CERTIFICATE" ]; then + if [ -f "$SSL_CERTIFICATE" ]; then + /bin/busybox wget --tries=1 --spider --no-check-certificate -q https://localhost:3000/status || exit 1 + exit 0 + fi +fi + +if [ -f "/databunker/certs/server.cer" ]; then + /bin/busybox wget --tries=1 --spider --no-check-certificate -q https://localhost:3000/status || exit 1 + exit 0 +fi + +CERT_FILE=`/bin/busybox sed -n -e '/ssl_certificate:/ s/ .*ssl_certificate: "\(.*\)"/\1/p' /databunker/conf/databunker.yaml` +if [ -n "$CERT_FILE" ]; then + if [ -f "$CERT_FILE" ]; then + /bin/busybox wget --tries=1 --spider --no-check-certificate -q https://localhost:3000/status || exit 1 + exit 0 + fi +fi + +# by default check http port +/bin/busybox wget --tries=1 --spider -q http://localhost:3000/status || exit 1