From 26bca2666d44e94bb865ba4ea782bd6494813607 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 25 Jun 2022 09:30:20 -0700 Subject: [PATCH] Remove key.json file if it appears to be corrupted (#1706) (#1988) * Remove key.json file if it appears to be corrupted (#1706) * Check with jq if key.json is parsable --- .../etc/systemd/system/docker.service.d/failure.conf | 3 +++ .../rootfs-overlay/usr/libexec/docker-failure | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100755 buildroot-external/rootfs-overlay/usr/libexec/docker-failure diff --git a/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/failure.conf b/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/failure.conf index 128fbd50964..8aae3831159 100644 --- a/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/failure.conf +++ b/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/failure.conf @@ -1,2 +1,5 @@ [Unit] FailureAction=reboot + +[Service] +ExecStopPost=/usr/libexec/docker-failure diff --git a/buildroot-external/rootfs-overlay/usr/libexec/docker-failure b/buildroot-external/rootfs-overlay/usr/libexec/docker-failure new file mode 100755 index 00000000000..493b00d7154 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/libexec/docker-failure @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ "$SERVICE_RESULT" = "exit-code" ] && [ "$EXIT_STATUS" = "1" ]; then + echo "Docker exited with exit status 1, this might be caused by corrupted key.json." + size=$(stat -c %s "/etc/docker/key.json") + echo "key.json: ${size} bytes" + if ! jq < "/etc/docker/key.json" > /dev/null || [ "${size}" -eq 0 ]; then + echo "key.json appears to be corrupted, it is not parsable. Removing it." + rm -f "/etc/docker/key.json" + fi +fi