Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM alpine:3.21 AS base

ENV NODE_ENV=production
WORKDIR /app
RUN apk add --no-cache tzdata eudev tini nodejs
RUN apk add --no-cache tzdata eudev tini nodejs file

# Dependencies and build
FROM base AS deps
Expand Down
28 changes: 28 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#!/bin/sh
set -e

sanity_check_database_db() { # <path_to_database_db_file>
# 'file' should be availabe in the container
MIMETYPE=`file -b -i "${1:?}" | sed 's/;.*//; q;'`
case "${MIMETYPE:-}" in
application/*json|application/*jason)
true
;;
*)
echo "Database contents of ${1:-} was not recognized as being JSON, rather ${MIMETYPE:-N/A}" 1>&2
false
;;
esac
}

if [ ! -z "$ZIGBEE2MQTT_DATA" ]; then
DATA="$ZIGBEE2MQTT_DATA"
else
Expand All @@ -9,4 +23,18 @@ fi

echo "Using '$DATA' as data directory"

DATABASE="$DATA/database.db"
if [ -f "$DATABASE" ]; then
if sanity_check_database_db "$DATABASE"; then
echo "Database file $DATABASE looks sane"
else
echo "Database file $DATABASE did not pass the sanity check!" 1>&2
DATETIMESTAMP=`date +'%Y-%m-%dT%H:%M:%S%z'` # same format as -Isec
RENAMED="$DATABASE.$DATETIMESTAMP~"
mv "$DATABASE" "$RENAMED"
echo "Renamed database file $DATABASE to $RENAMED"
echo "Starting without database file"
fi
fi

exec "$@"
Loading