[BUGFIX] Fix Docker healthcheck script (#1485)

* [MISC] Update Docker healthcheck script

This change now determines the host for Docker healthcheck from the `configuration.yml` that Authelia is started with.

The script has also been run through shellcheck and terminated with a newline in hopes to resolve a number of unreproducible issues.

* Fix healthcheck failing because of CRLF in configuration.yml (#1483)

The configuration.yml might contain CRLF characters. If that's the case, they are included in the results of sed, which breaks the healthcheck, so remove any CR characters in the host/port variables.

Co-authored-by: Berisan <berisan@berisan.dev>
pull/1486/head
Amir Zarrinkafsh 2020-11-24 13:04:06 +11:00 committed by GitHub
parent 3832b55312
commit 1ed59957a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -1,17 +1,22 @@
#!/bin/sh #!/bin/sh
AUTHELIA_CONFIG=$(ps | grep authelia | awk '{print $6}' | head -1) AUTHELIA_CONFIG=$(pgrep -af authelia | awk '{print $4}')
AUTHELIA_SCHEME=$(cat "${AUTHELIA_CONFIG}" | grep ^tls) AUTHELIA_SCHEME=$(grep ^tls "${AUTHELIA_CONFIG}")
AUTHELIA_PORT=$(cat "${AUTHELIA_CONFIG}" | grep ^port | sed -e 's/port: //') AUTHELIA_HOST=$(grep ^host "${AUTHELIA_CONFIG}" | sed -e 's/host: //' -e 's/\r//')
AUTHELIA_PORT=$(grep ^port "${AUTHELIA_CONFIG}" | sed -e 's/port: //' -e 's/\r//')
if [[ -z ${AUTHELIA_PORT} ]]; then if [ -z "${AUTHELIA_SCHEME}" ]; then
AUTHELIA_PORT=9091
fi
if [[ -z ${AUTHELIA_SCHEME} ]]; then
AUTHELIA_SCHEME=http AUTHELIA_SCHEME=http
else else
AUTHELIA_SCHEME=https AUTHELIA_SCHEME=https
fi fi
wget --quiet --tries=1 --spider ${AUTHELIA_SCHEME}://localhost:${AUTHELIA_PORT}/api/state || exit 1 if [ -z "${AUTHELIA_HOST}" ] || [ "${AUTHELIA_HOST}" = "0.0.0.0" ]; then
AUTHELIA_HOST=localhost
fi
if [ -z "${AUTHELIA_PORT}" ]; then
AUTHELIA_PORT=9091
fi
wget --quiet --tries=1 --spider "${AUTHELIA_SCHEME}://${AUTHELIA_HOST}:${AUTHELIA_PORT}/api/state" || exit 1