From 1d3132e447b4d3eae673ab04e519275f2e296e52 Mon Sep 17 00:00:00 2001 From: Rai Date: Thu, 20 Oct 2022 23:29:23 -0700 Subject: [PATCH] Check both http and https in DockerHealthcheck I've been getting Docker reporting my Trilium container as unhealthy because wget was trying to talk HTTP to it while it was expecting HTTPS. --- DockerHealthcheck.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/DockerHealthcheck.sh b/DockerHealthcheck.sh index 786166602..0efe4b2d4 100755 --- a/DockerHealthcheck.sh +++ b/DockerHealthcheck.sh @@ -1,6 +1,13 @@ #!/bin/sh -if wget --spider -S "127.0.0.1:8080/api/health-check" 2>&1 | awk 'NR==2' | grep -w "HTTP/1.1 200 OK" ; then - exit 0 -else - exit 1 -fi + +# Try connecting to /api/health-check using both http and https. +# TODO: we should only be connecting with the actual protocol that is enabled +# TODO: this assumes we use the default port 8080 + +for proto in http https; do + if wget --spider -S "$proto://127.0.0.1:8080/api/health-check" 2>&1 | awk 'NR==2' | grep -w "HTTP/1.1 200 OK" ; then + exit 0 + fi +done + +exit 1