2024-03-29 04:39:44 +01:00
|
|
|
#!/bin/bash
|
2020-05-30 01:12:20 +02:00
|
|
|
set -x
|
|
|
|
set -e
|
2013-04-22 17:06:54 +02:00
|
|
|
|
2024-03-29 04:39:44 +01:00
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
LOCALDISK=$(
|
|
|
|
nvme list -o json \
|
|
|
|
| jq -r '.Devices[] | select(.ModelNumber | contains("Instance Storage")) | .DevicePath' \
|
|
|
|
| head -n1
|
|
|
|
)
|
|
|
|
|
|
|
|
if [ -z "$LOCALDISK" ]; then
|
|
|
|
echo "No instance storage found!"
|
|
|
|
nvme list
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-04-22 17:06:54 +02:00
|
|
|
|
2021-05-18 05:35:41 +02:00
|
|
|
if ! grep -q "$LOCALDISK" /etc/fstab; then
|
2024-03-29 04:44:18 +01:00
|
|
|
echo "$LOCALDISK /srv/data xfs nofail,noatime 1 1" >>/etc/fstab
|
2020-05-30 01:12:20 +02:00
|
|
|
fi
|
2016-07-19 03:37:50 +02:00
|
|
|
|
2024-03-29 04:44:18 +01:00
|
|
|
if [ ! -d /srv/data ]; then
|
|
|
|
mkdir /srv/data
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! mountpoint -q /srv/data; then
|
2021-05-18 05:35:41 +02:00
|
|
|
mkfs.xfs "$LOCALDISK"
|
2024-03-29 04:44:18 +01:00
|
|
|
mount /srv/data
|
2020-05-30 01:12:20 +02:00
|
|
|
fi
|
2013-04-17 22:15:10 +02:00
|
|
|
|
2020-05-30 01:12:20 +02:00
|
|
|
if [ ! -L /var/lib/postgresql ]; then
|
|
|
|
service postgresql stop
|
|
|
|
if [ -e /var/lib/postgresql ]; then
|
2020-10-27 23:33:35 +01:00
|
|
|
mv /var/lib/postgresql "/root/postgresql-data-$(date +'%m-%d-%Y-%T')"
|
2020-05-30 01:12:20 +02:00
|
|
|
fi
|
2024-03-29 04:44:18 +01:00
|
|
|
ln -s /srv/data/postgresql/ /var/lib
|
2020-05-30 01:12:20 +02:00
|
|
|
fi
|
2013-05-08 22:54:25 +02:00
|
|
|
|
2024-03-29 04:44:18 +01:00
|
|
|
if [ ! -e "/srv/data/postgresql" ]; then
|
2020-05-30 01:12:20 +02:00
|
|
|
service postgresql stop
|
2024-03-29 04:44:18 +01:00
|
|
|
mkdir "/srv/data/postgresql"
|
|
|
|
chown postgres:postgres /srv/data/postgresql
|
2020-05-30 01:12:20 +02:00
|
|
|
fi
|