Skip to content

Commit

Permalink
Merge pull request #1657 from nextcloud/enh/noid/fix-healtchecks
Browse files Browse the repository at this point in the history
fix healthcheck for nextcloud and database
  • Loading branch information
szaimen authored Jan 2, 2023
2 parents cd06678 + ed54835 commit 0ef29ff
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Containers/nextcloud/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand All @@ -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
HEALTHCHECK CMD sudo -E -u www-data bash /healthcheck.sh
7 changes: 7 additions & 0 deletions Containers/nextcloud/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

nc -z "$POSTGRES_HOST" 5432 || exit 0

if ! nc -z localhost 9000 || ! nc -z localhost 7867; then
exit 1
fi
9 changes: 6 additions & 3 deletions Containers/postgresql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
HEALTHCHECK CMD healthcheck.sh
5 changes: 5 additions & 0 deletions Containers/postgresql/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0ef29ff

Please sign in to comment.