- runner: export sbin-inclusive PATH (util-linux tools live in /usr/sbin) - 001: read /proc/swaps instead of swapon(8) - 005: resolve /dev/disk/by-uuid symlink instead of findfs(8); report ? (exit 2) when the UUID cannot be resolved
51 lines
2.2 KiB
Bash
51 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
# 005-mount-pgdata - Mount the dedicated 20G data disk (/dev/sdb, ext4)
|
|
# at /var/lib/postgresql so the PostgreSQL cluster lives on its own disk.
|
|
# Mounted by UUID (stable across device reordering), noatime for DB workload.
|
|
# up: fstab entry + mount (idempotent; refuses if mountpoint holds data)
|
|
# down: unmount + remove fstab entry (data on the disk is preserved)
|
|
set -euo pipefail
|
|
|
|
DISK_UUID=d44ad362-947a-46de-acbf-5530f83e4506
|
|
MOUNTPOINT=/var/lib/postgresql
|
|
FSTAB_LINE="UUID=$DISK_UUID $MOUNTPOINT ext4 defaults,noatime 0 2"
|
|
|
|
case "${1:-}" in
|
|
up)
|
|
if findmnt -rn "$MOUNTPOINT" >/dev/null; then
|
|
echo " $MOUNTPOINT already mounted - skipping"
|
|
exit 0
|
|
fi
|
|
dev=$(findfs UUID="$DISK_UUID") || {
|
|
echo "disk with UUID=$DISK_UUID not found - is /dev/sdb attached?" >&2
|
|
exit 1
|
|
}
|
|
# Never mount over existing data - it would be silently hidden
|
|
if [[ -d $MOUNTPOINT ]] && find "$MOUNTPOINT" -mindepth 1 -print -quit | grep -q .; then
|
|
echo "refusing to mount: $MOUNTPOINT exists and is not empty" >&2
|
|
exit 1
|
|
fi
|
|
mkdir -p "$MOUNTPOINT"
|
|
grep -q "^UUID=$DISK_UUID" /etc/fstab || echo "$FSTAB_LINE" >> /etc/fstab
|
|
mount "$MOUNTPOINT" # via fstab entry - also validates it
|
|
echo " $dev mounted at $MOUNTPOINT (noatime, fstab entry added)"
|
|
;;
|
|
status)
|
|
src=$(findmnt -rn -o SOURCE "$MOUNTPOINT" 2>/dev/null || true)
|
|
want=$(readlink -f "/dev/disk/by-uuid/$DISK_UUID" 2>/dev/null || true)
|
|
[[ -n $want ]] || { echo "? cannot resolve UUID=$DISK_UUID"; exit 2; }
|
|
[[ -n $src ]] || { echo "DRIFT $MOUNTPOINT not mounted"; exit 1; }
|
|
[[ $src == "$want" ]] || { echo "DRIFT $MOUNTPOINT mounted from $src (want $want)"; exit 1; }
|
|
grep -q "^UUID=$DISK_UUID $MOUNTPOINT " /etc/fstab \
|
|
|| { echo "DRIFT fstab entry missing"; exit 1; }
|
|
echo "OK $src at $MOUNTPOINT + fstab entry"
|
|
;;
|
|
down)
|
|
# sysmig rolls back in reverse order, so 006 (postgres) is already down
|
|
if findmnt -rn "$MOUNTPOINT" >/dev/null; then umount "$MOUNTPOINT"; fi
|
|
sed -i "\|^UUID=$DISK_UUID|d" /etc/fstab
|
|
rmdir "$MOUNTPOINT" 2>/dev/null || true # keep dir if data remains
|
|
echo " $MOUNTPOINT unmounted + fstab entry removed (disk data kept)"
|
|
;;
|
|
esac
|