Make self healing capabilities more robust (#960)

In case a container image is corrupted `docker inspect` might fail:
  # docker inspect --format='{{.Id}}' "${SUPERVISOR_IMAGE}"

  Error response from daemon: readlink /mnt/data/docker/overlay2: invalid argument

In that same state the `docker images` command still shows the images.
Since `docker inspect` returns an error SUPERVISOR_IMAGE_ID will be empty
and a simple `docker pull` will be attempted. That does not suffice to
recover from a corrupted container image.

Use `docker images` to get the image ids and make sure to delete all
image ids found by that command.

Also don't use RuntimeDirectory since it deletes the runtime directory
between the service start attempts which defeats the purpose.
This commit is contained in:
Stefan Agner 2020-11-09 13:05:54 +01:00 committed by GitHub
parent 094208492e
commit 4f28a284be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -13,7 +13,6 @@ ConditionPathExists=/run/docker.sock
Type=simple Type=simple
Restart=always Restart=always
RestartSec=5s RestartSec=5s
RuntimeDirectory=supervisor
ExecStartPre=-/usr/bin/docker stop hassio_supervisor ExecStartPre=-/usr/bin/docker stop hassio_supervisor
ExecStart=/usr/sbin/hassos-supervisor ExecStart=/usr/sbin/hassos-supervisor
ExecStop=-/usr/bin/docker stop hassio_supervisor ExecStop=-/usr/bin/docker stop hassio_supervisor

View File

@ -12,7 +12,7 @@ set -e
SUPERVISOR_STARTUP_MARKER="/run/supervisor/startup-marker" SUPERVISOR_STARTUP_MARKER="/run/supervisor/startup-marker"
SUPERVISOR_IMAGE="homeassistant/${SUPERVISOR_ARCH}-hassio-supervisor" SUPERVISOR_IMAGE="homeassistant/${SUPERVISOR_ARCH}-hassio-supervisor"
SUPERVISOR_DATA=/mnt/data/supervisor SUPERVISOR_DATA=/mnt/data/supervisor
SUPERVISOR_IMAGE_ID=$(docker inspect --format='{{.Id}}' "${SUPERVISOR_IMAGE}" || echo "") SUPERVISOR_IMAGE_ID=$(docker images --no-trunc --filter "reference=${SUPERVISOR_IMAGE}:latest" --format "{{.ID}}" || echo "")
SUPERVISOR_CONTAINER_ID=$(docker inspect --format='{{.Image}}' hassio_supervisor || echo "") SUPERVISOR_CONTAINER_ID=$(docker inspect --format='{{.Image}}' hassio_supervisor || echo "")
# Check if previous run left the startup-marker in place. If so, we assume the # Check if previous run left the startup-marker in place. If so, we assume the
@ -22,11 +22,15 @@ if [ -f "${SUPERVISOR_STARTUP_MARKER}" ]; then
echo "[WARNING] Supervisor container did not remove the startup marker file. Assuming container image or container corruption." echo "[WARNING] Supervisor container did not remove the startup marker file. Assuming container image or container corruption."
docker container rm --force hassio_supervisor || true docker container rm --force hassio_supervisor || true
SUPERVISOR_CONTAINER_ID="" SUPERVISOR_CONTAINER_ID=""
docker rmi --force "${SUPERVISOR_IMAGE_ID}" || true # Make sure we delete all supervisor images
SUPERVISOR_IMAGE_IDS=$(docker images --no-trunc --filter "reference=${SUPERVISOR_IMAGE}" --format "{{.ID}}" | uniq || echo "")
docker image rm --force "${SUPERVISOR_IMAGE_IDS}" || true
SUPERVISOR_IMAGE_ID="" SUPERVISOR_IMAGE_ID=""
fi fi
# If Supervisor image is missing, pull it # If Supervisor image is missing, pull it
mkdir -p "$(dirname ${SUPERVISOR_STARTUP_MARKER})"
touch ${SUPERVISOR_STARTUP_MARKER}
if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then
# Get the latest from update information # Get the latest from update information
# Using updater information instead of config. If the config version is # Using updater information instead of config. If the config version is
@ -80,6 +84,5 @@ fi
# Run supervisor # Run supervisor
mkdir -p ${SUPERVISOR_DATA} mkdir -p ${SUPERVISOR_DATA}
touch ${SUPERVISOR_STARTUP_MARKER}
echo "[INFO] Starting the Supervisor..." echo "[INFO] Starting the Supervisor..."
exec docker container start --attach hassio_supervisor exec docker container start --attach hassio_supervisor