Files
lislgosms/tools/deploy/check-data-storage.sh
T

33 lines
1.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
fail() { echo "CMPP data storage unavailable: $*" >&2; exit 1; }
expected_uuid=$(cat /etc/cmpp-platform/data-disk.uuid) || fail "expected UUID configuration is missing"
[[ "$expected_uuid" =~ ^[a-f0-9-]{36}$ ]] || fail "invalid expected UUID"
mountpoint -q /data || fail "/data is not mounted"
[[ "$(findmnt -rn -M /data -o UUID)" == "$expected_uuid" ]] || fail "/data UUID mismatch"
[[ "$(cat /data/.cmpp-data-disk.uuid)" == "$expected_uuid" ]] || fail "data marker mismatch"
case ",$(findmnt -rn -M /data -o OPTIONS)," in *,rw,*) ;; *) fail "/data is read-only";; esac
check_one() {
local role="$1" source target
case "$role" in
postgresql) source=/data/postgresql; target=/var/lib/pgsql ;;
redis) source=/data/redis; target=/var/lib/redis ;;
minio) source=/data/minio; target=/var/lib/minio ;;
*) fail "unknown service $role" ;;
esac
mountpoint -q "$target" || fail "$target is not a mount point"
[[ "$(findmnt -rn -M "$target" -o UUID)" == "$expected_uuid" ]] || fail "$target UUID mismatch"
[[ "$(stat -Lc '%d:%i' "$source")" == "$(stat -Lc '%d:%i' "$target")" ]] || fail "$target does not map to $source"
case ",$(findmnt -rn -M "$target" -o OPTIONS)," in *,rw,*) ;; *) fail "$target is read-only";; esac
case "$role" in
postgresql) [[ -s "$target/data/PG_VERSION" && -d "$target/data/base" ]] || fail "existing PostgreSQL cluster is missing" ;;
redis) [[ -s "$target/dump.rdb" ]] || fail "existing Redis RDB is missing" ;;
minio) [[ -s "$target/.minio.sys/format.json" ]] || fail "existing MinIO format is missing" ;;
esac
echo "CMPP storage OK: $role $target -> $source UUID=$expected_uuid"
}
case "${1:-all}" in
all) check_one postgresql; check_one redis; check_one minio ;;
*) check_one "$1" ;;
esac