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
This commit is contained in:
Stefan Agner 2022-06-25 09:30:20 -07:00 committed by GitHub
parent 7708de0c65
commit 26bca2666d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -1,2 +1,5 @@
[Unit]
FailureAction=reboot
[Service]
ExecStopPost=/usr/libexec/docker-failure

View File

@ -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