Commit 33b5c76 claimed to harden Pi-hole on both DNS nodes but only
modified markdown — the working docker-compose.yml, gravity-validate.sh,
healthcheck, and autoheal config were never written to the repo, leaving
the DNS hardening unreproducible from version control.
This commits the live, verified-working config from the boxes into
netinfra/pihole/:
- docker-compose.yml (shm_size 1024M root-cause fix, healthcheck, autoheal)
- gravity-validate.sh (pre-start SQLite header check, auto-quarantine corrupt DB)
- .env.example (web UI password templated; real .env gitignored)
Defends against the gravity.db / /dev/shm corruption production outage.
The live password is templated as ${PIHOLE_WEB_PASSWORD} so no secret
enters git.
[#376]
29 lines
1.2 KiB
Bash
Executable File
29 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# gravity-validate.sh — pre-start integrity check for Pi-hole's gravity.db
|
|
#
|
|
# Runs as the container entrypoint. If gravity.db is empty or has an invalid
|
|
# SQLite header (the symptom of the /dev/shm corruption outage), move it aside
|
|
# so Pi-hole regenerates a clean DB on start instead of crashing.
|
|
set -e
|
|
GRAVITY_DB="/etc/pihole/gravity.db"
|
|
TIMESTAMP=$(date +%Y%m%d%H%M%S)
|
|
|
|
if [ -f "$GRAVITY_DB" ]; then
|
|
if [ ! -s "$GRAVITY_DB" ]; then
|
|
echo "[gravity-validate] gravity.db is empty, moving aside"
|
|
mv "$GRAVITY_DB" "${GRAVITY_DB}.corrupt.${TIMESTAMP}"
|
|
else
|
|
HEADER=$(head -c 15 "$GRAVITY_DB" 2>/dev/null || true)
|
|
if [ "$HEADER" != "SQLite format 3" ]; then
|
|
echo "[gravity-validate] gravity.db invalid header, moving aside"
|
|
mv "$GRAVITY_DB" "${GRAVITY_DB}.corrupt.${TIMESTAMP}"
|
|
fi
|
|
fi
|
|
fi
|
|
# Keep only the 3 most recent corrupt backups (names carry a timestamp,
|
|
# so lexical reverse-sort = newest-first).
|
|
find /etc/pihole -maxdepth 1 -name 'gravity.db.corrupt.*' -print 2>/dev/null \
|
|
| sort -r | tail -n +4 | xargs -r rm -f
|
|
echo "[gravity-validate] OK, starting Pi-hole"
|
|
exec /usr/bin/start.sh "$@"
|