From 54c642e787af3908866afe7df0304fb76bd31e7f Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 2 Jan 2023 18:16:12 +0100 Subject: [PATCH 1/2] fix healthcheck for nextcloud and database Signed-off-by: Simon L --- Containers/nextcloud/Dockerfile | 5 +++-- Containers/nextcloud/healthcheck.sh | 7 +++++++ Containers/postgresql/Dockerfile | 9 ++++++--- Containers/postgresql/healthcheck.sh | 5 +++++ 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 Containers/nextcloud/healthcheck.sh create mode 100644 Containers/postgresql/healthcheck.sh diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index 60dffc10..66f0eb6f 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -250,7 +250,8 @@ RUN set -ex; \ chmod +x /cron.sh && \ chmod +x /notify.sh && \ chmod +x /notify-all.sh && \ - chmod +x /activate-collabora.sh + chmod +x /activate-collabora.sh && \ + chmod +x healthcheck.sh RUN set -ex; \ mkdir /mnt/ncdata; \ @@ -264,4 +265,4 @@ RUN echo "root:$(openssl rand -base64 12)" | chpasswd USER root ENTRYPOINT ["/start.sh"] -HEALTHCHECK CMD (sudo -u www-data nc -z "$POSTGRES_HOST" 5432 || exit 0) && (sudo -u www-data nc -z localhost 9000 && sudo -u www-data nc -z localhost 7867) || exit 1 \ No newline at end of file +HEALTHCHECK CMD /healthcheck.sh diff --git a/Containers/nextcloud/healthcheck.sh b/Containers/nextcloud/healthcheck.sh new file mode 100644 index 00000000..960ee6c7 --- /dev/null +++ b/Containers/nextcloud/healthcheck.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +sudo -u www-data nc -z "$POSTGRES_HOST" 5432 || exit 0 + +if ! sudo -u www-data nc -z localhost 9000 || ! sudo -u www-data nc -z localhost 7867; then + exit 1 +fi diff --git a/Containers/postgresql/Dockerfile b/Containers/postgresql/Dockerfile index ea8daff4..5bd02dd7 100644 --- a/Containers/postgresql/Dockerfile +++ b/Containers/postgresql/Dockerfile @@ -17,9 +17,12 @@ RUN set -ex; \ chown -R postgres:postgres "$PGDATA" COPY start.sh /usr/bin/ +COPY healthcheck.sh /usr/bin/ COPY init-user-db.sh /docker-entrypoint-initdb.d/ -RUN chmod +x /usr/bin/start.sh; \ - chmod +xr /docker-entrypoint-initdb.d/init-user-db.sh +RUN set -ex; \ + chmod +x /usr/bin/start.sh; \ + chmod +xr /docker-entrypoint-initdb.d/init-user-db.sh; \ + chmod +x /usr/bin/healthcheck.sh RUN mkdir /mnt/data; \ chown postgres:postgres /mnt/data; @@ -32,4 +35,4 @@ RUN echo "root:$(openssl rand -base64 12)" | chpasswd USER postgres ENTRYPOINT ["start.sh"] -HEALTHCHECK CMD (test -f "/mnt/data/backup-is-running" && exit 0) && psql -d "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "select now()" || exit 1 \ No newline at end of file +HEALTHCHECK CMD healthcheck.sh diff --git a/Containers/postgresql/healthcheck.sh b/Containers/postgresql/healthcheck.sh new file mode 100644 index 00000000..064bfbcb --- /dev/null +++ b/Containers/postgresql/healthcheck.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +test -f "/mnt/data/backup-is-running" && exit 0 + +psql -d "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "select now()" || exit 1 From ed5483500aa04d528ceb6ace165efe3bbbde765d Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 2 Jan 2023 18:24:17 +0100 Subject: [PATCH 2/2] Address review Signed-off-by: Simon L Co-Authored-By: Zoey --- Containers/nextcloud/Dockerfile | 4 ++-- Containers/nextcloud/healthcheck.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index 66f0eb6f..881ee0c6 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -251,7 +251,7 @@ RUN set -ex; \ chmod +x /notify.sh && \ chmod +x /notify-all.sh && \ chmod +x /activate-collabora.sh && \ - chmod +x healthcheck.sh + chmod +x /healthcheck.sh RUN set -ex; \ mkdir /mnt/ncdata; \ @@ -265,4 +265,4 @@ RUN echo "root:$(openssl rand -base64 12)" | chpasswd USER root ENTRYPOINT ["/start.sh"] -HEALTHCHECK CMD /healthcheck.sh +HEALTHCHECK CMD sudo -E -u www-data bash /healthcheck.sh diff --git a/Containers/nextcloud/healthcheck.sh b/Containers/nextcloud/healthcheck.sh index 960ee6c7..df87360c 100644 --- a/Containers/nextcloud/healthcheck.sh +++ b/Containers/nextcloud/healthcheck.sh @@ -1,7 +1,7 @@ #!/bin/bash -sudo -u www-data nc -z "$POSTGRES_HOST" 5432 || exit 0 +nc -z "$POSTGRES_HOST" 5432 || exit 0 -if ! sudo -u www-data nc -z localhost 9000 || ! sudo -u www-data nc -z localhost 7867; then +if ! nc -z localhost 9000 || ! nc -z localhost 7867; then exit 1 fi