diff --git a/meta-balena-common/recipes-containers/balena/balena/balena-healthcheck b/meta-balena-common/recipes-containers/balena/balena/balena-healthcheck index 19a1f1b24e..df6688c061 100644 --- a/meta-balena-common/recipes-containers/balena/balena/balena-healthcheck +++ b/meta-balena-common/recipes-containers/balena/balena/balena-healthcheck @@ -8,5 +8,21 @@ CONTAINERD_SOCKET="/run/balena-engine/containerd/balena-engine-containerd.sock" # Check if balena-engine-daemon is responding. curl --fail --unix-socket $BALENAD_SOCKET http:/v1.40/_ping > /dev/null 2>&1 +# Due to a non-atomic file creation and writing operation in containerd, we +# sometimes end up with an empty `uuid` file. This causes `ctr version` (and +# hence the health check) to fail. We therefore remove this file if it is +# present and empty. See https://github.com/balena-os/balena-engine/issues/322 +UUID_FILE="/mnt/data/docker/containerd/daemon/io.containerd.grpc.v1.introspection/uuid" +if [ -f "$UUID_FILE" -a ! -s "$UUID_FILE" ]; then + echo "healthcheck: removing empty $UUID_FILE" + rm -f "$UUID_FILE" +fi + # Check if balena-engine-containerd is responding. balena-engine-containerd-ctr --address $CONTAINERD_SOCKET version > /dev/null 2>&1 + +# The uuid file is expected to exist and be non-empty after `ctr version`. If +# this is not the case, log and record the event. +if [ -f "$UUID_FILE" -a ! -s "$UUID_FILE" ]; then + echo "healthcheck: $UUID_FILE empty after 'ctr version'" +fi