Add a disk space check before upgrading PostgreSQL.
authorGuo Xiang Tan <tgx_world@hotmail.com>
Thu, 12 Apr 2018 07:14:14 +0000 (15:14 +0800)
committerGuo Xiang Tan <tgx_world@hotmail.com>
Thu, 12 Apr 2018 07:14:14 +0000 (15:14 +0800)
templates/postgres.template.yml

index 47f98765b089ae9bc7dcb92c2783af8100d2c0fa..50c8f01affc5dbe36b1b68a4efe9d6e9e5adad32 100644 (file)
@@ -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