From 448a70b9931f0879813c88998a565cf2ecf10653 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 12 Apr 2018 15:14:14 +0800 Subject: [PATCH] Add a disk space check before upgrading PostgreSQL. --- templates/postgres.template.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml index 47f9876..50c8f01 100644 --- a/templates/postgres.template.yml +++ b/templates/postgres.template.yml @@ -45,7 +45,6 @@ run: mkdir -p /var/log/postgres exec svlogd /var/log/postgres - - file: path: /etc/runit/3.d/99-postgres chmod: "+x" @@ -61,7 +60,16 @@ run: PG_MAJOR_OLD=`cat /shared/postgres_data/PG_VERSION` if [ ! "10" = "$PG_MAJOR_OLD" ]; then - echo Upgrading PostgreSQL to from version ${PG_MAJOR_OLD} to 10 + echo Upgrading PostgreSQL from version ${PG_MAJOR_OLD} to 10 + free_disk=$(df /var | tail -n 1 | awk '{print $4}') + required=$(($(du -s /shared/postgres_data | awk '{print $1}') * 2)) + + if [ "$free_disk" -lt "$required" ]; then + echo "WARNING: Upgrading PostgresSQL would require an addtional $(du -sh /shared/postgres_data | awk '{print $1}') of disk space" + echo "Please free up some space, or expand your disk, before continuing." + exit 1 + fi + rm -fr /shared/postgres_data_new install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/10/bin/initdb -D /shared/postgres_data_new || exit 0 apt-get update -- 2.25.1