@@ -5,10 +5,10 @@ set -eu
55PACKAGE_DIR=/var/vcap/packages/postgres-10
66PACKAGE_DIR_OLD=/var/vcap/packages/postgres-9.4
77
8- STORE_DIR =/var/vcap/store
8+ PERSISTENT_DISK_DIR =/var/vcap/store
99
10- DATA_DIR= $STORE_DIR /postgres-10
11- DATA_DIR_OLD= $STORE_DIR /postgres-9.4
10+ STORE_DIR= ${PERSISTENT_DISK_DIR} /postgres-10
11+ STORE_DIR_OLD= ${PERSISTENT_DISK_DIR} /postgres-9.4
1212
1313USER=' <%= p("postgres.user") %>'
1414
2626
2727# We cannot kill the following conditional
2828# because initdb is very picky about looking at an empty dir
29- if [ ! -d $DATA_DIR ] || [ ! -f $DATA_DIR /postgresql.conf ]; then
30- mkdir -p $DATA_DIR
31- chown vcap:vcap $DATA_DIR
29+ if [ ! -d ${STORE_DIR} ] || [ ! -f ${STORE_DIR} /postgresql.conf ]; then
30+ mkdir -p " ${STORE_DIR} "
31+ chown vcap:vcap " ${STORE_DIR} "
3232
3333 # initdb creates data directories
34- su - vcap -c " $PACKAGE_DIR /bin/initdb -E utf8 -D $DATA_DIR "
34+ su - vcap -c " ${ PACKAGE_DIR} /bin/initdb -E utf8 -D ${STORE_DIR} "
3535
36- touch /var/vcap/store/postgres-10/ fresh
36+ touch " ${STORE_DIR} / fresh"
3737
3838 if [ $? != 0 ]; then
3939 echo " ERROR: Unable to Initialize Postgres DB"
4040 exit 1
4141 fi
4242
43- echo " host all $USER 0.0.0.0/0 md5" >> $DATA_DIR /pg_hba.conf
43+ echo " host all $USER 0.0.0.0/0 md5" >> " ${STORE_DIR} /pg_hba.conf"
4444
45- mkdir -p $DATA_DIR /pg_log
46- chown vcap:vcap $DATA_DIR /pg_log
45+ mkdir -p " ${STORE_DIR} /pg_log"
46+ chown vcap:vcap " ${STORE_DIR} /pg_log"
4747fi
4848
49- if [[ -f /var/vcap/store/postgres-10 /fresh ]] ; then
50- if [[ -d /var/vcap/store/postgres-9.4 ]] ; then
49+ if [[ -f ${STORE_DIR} /fresh ]] ; then
50+ if [[ -d ${STORE_DIR_OLD} ]] ; then
5151 echo " checking status of postgres-9.4..."
52- if ! ${PACKAGE_DIR_OLD} /bin/pg_controldata " ${DATA_DIR_OLD } " | grep -E " Database cluster state:\s+shut down" ; then
52+ if ! " ${PACKAGE_DIR_OLD} /bin/pg_controldata" " ${STORE_DIR_OLD } " | grep -E " Database cluster state:\s+shut down" ; then
5353 echo " postgres-9.4 did not shut down cleanly"
5454 echo " repairing postgres-9.4. cluster state..."
5555
56- su - vcap -c " $PACKAGE_DIR_OLD /bin/postgres -D $DATA_DIR_OLD " &
56+ su - vcap -c " ${ PACKAGE_DIR_OLD} /bin/postgres -D ${STORE_DIR_OLD} " &
5757 postgres_pid=$!
5858
5959 count=0
60- while ! ${PACKAGE_DIR_OLD} /bin/pg_isready -t 30 -U postgres; do
60+ while ! " ${PACKAGE_DIR_OLD} /bin/pg_isready" -t 30 -U postgres; do
6161 echo " waiting for postgres-9.4 to start..."
6262 sleep 1
6363 count=$(( count + 1 ))
@@ -72,24 +72,24 @@ if [[ -f /var/vcap/store/postgres-10/fresh ]] ; then
7272 fi
7373
7474 echo " copying contents of postgres-9.4 to postgres-10 for postgres upgrade..."
75- su - vcap -c " /var/vcap/packages/postgres-10 /bin/pg_upgrade \
76- --old-bindir=$PACKAGE_DIR_OLD /bin \
77- --new-bindir=$PACKAGE_DIR /bin \
78- --old-datadir=$DATA_DIR_OLD \
79- --new-datadir=$DATA_DIR "
75+ su - vcap -c " ${PACKAGE_DIR} /bin/pg_upgrade \
76+ --old-bindir=${ PACKAGE_DIR_OLD} /bin \
77+ --new-bindir=${ PACKAGE_DIR} /bin \
78+ --old-datadir=${STORE_DIR_OLD} \
79+ --new-datadir=${STORE_DIR} "
8080
8181 echo " successfully upgraded from postgres-9.4"
82- rm -rf ' /var/vcap/store/postgres-9 '
82+ rm -rf " ${STORE_DIR_OLD} "
8383 fi
8484
85- rm /var/vcap/store/postgres-10/ fresh
85+ rm " ${STORE_DIR} / fresh"
8686fi
8787
8888# "bpm enforces its own locking around process operations to avoid race conditions"
8989# from docs: https://bosh.io/docs/bpm/runtime/
9090# so postmaster.pid is stale of it still exists
9191# remove it to prevent running into:
9292# FATAL: lock file "postmaster.pid" already exists
93- if [[ -f /var/vcap/store/postgres-10 /postmaster.pid ]] ; then
94- rm /var/vcap/store/postgres-10/ postmaster.pid
93+ if [[ -f ${STORE_DIR} /postmaster.pid ]] ; then
94+ rm " ${STORE_DIR} / postmaster.pid"
9595fi
0 commit comments