Skip to content

Commit 5675d8c

Browse files
bgandoncunnie
authored andcommitted
Avoid misleading variable names + Fix removal of 'postgres-10' persistent data after successful upgrade to v13
1 parent 24ec8a2 commit 5675d8c

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

jobs/postgres-10/templates/pre-start.erb

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ set -eu
55
PACKAGE_DIR=/var/vcap/packages/postgres-10
66
PACKAGE_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

1313
USER='<%= p("postgres.user") %>'
1414

@@ -26,38 +26,38 @@ fi
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"
4747
fi
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"
8686
fi
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"
9595
fi

jobs/postgres/templates/pre-start.erb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ set -eu
55
PACKAGE_DIR=/var/vcap/packages/postgres-13
66
PACKAGE_DIR_OLD=/var/vcap/packages/postgres-10
77

8-
STORE_DIR=/var/vcap/store
8+
PERSISTENT_DISK_DIR=/var/vcap/store
99

10-
DATA_DIR=$STORE_DIR/postgres-13
11-
DATA_DIR_OLD=$STORE_DIR/postgres-10
10+
STORE_DIR=${PERSISTENT_DISK_DIR}/postgres-13
11+
STORE_DIR_OLD=${PERSISTENT_DISK_DIR}/postgres-10
1212

1313
USER='<%= p("postgres.user") %>'
1414

@@ -21,47 +21,47 @@ fi
2121

2222
# We cannot kill the following conditional
2323
# because initdb is very picky about looking at an empty dir
24-
if [ ! -d $DATA_DIR ] || [ ! -f $DATA_DIR/postgresql.conf ]; then
25-
mkdir -p $DATA_DIR
26-
chown vcap:vcap $DATA_DIR
24+
if [ ! -d ${STORE_DIR} ] || [ ! -f ${STORE_DIR}/postgresql.conf ]; then
25+
mkdir -p "${STORE_DIR}"
26+
chown vcap:vcap "${STORE_DIR}"
2727

2828
# initdb creates data directories
29-
su - vcap -c "$PACKAGE_DIR/bin/initdb -E utf8 -D $DATA_DIR"
29+
su - vcap -c "${PACKAGE_DIR}/bin/initdb -E utf8 -D ${STORE_DIR}"
3030

31-
touch /var/vcap/store/postgres-13/fresh
31+
touch "${STORE_DIR}/fresh"
3232

3333
if [ $? != 0 ]; then
3434
echo "ERROR: Unable to Initialize Postgres DB"
3535
exit 1
3636
fi
3737

38-
echo "host all $USER 0.0.0.0/0 md5" >> $DATA_DIR/pg_hba.conf
38+
echo "host all ${USER} 0.0.0.0/0 md5" >> "${STORE_DIR}/pg_hba.conf"
3939

40-
mkdir -p $DATA_DIR/pg_log
41-
chown vcap:vcap $DATA_DIR/pg_log
40+
mkdir -p "${STORE_DIR}/pg_log"
41+
chown vcap:vcap "${STORE_DIR}/pg_log"
4242
fi
4343

44-
if [[ -f /var/vcap/store/postgres-13/fresh ]] ; then
45-
if [[ -d /var/vcap/store/postgres-10 ]] ; then
44+
if [[ -f ${STORE_DIR}/fresh ]] ; then
45+
if [[ -d ${STORE_DIR_OLD} ]] ; then
4646
echo "copying contents of postgres-10 to postgres-13 for postgres upgrade..."
47-
su - vcap -c "$PACKAGE_DIR/bin/pg_upgrade \
48-
--old-bindir=$PACKAGE_DIR_OLD/bin \
49-
--new-bindir=$PACKAGE_DIR/bin \
50-
--old-datadir=$DATA_DIR_OLD \
51-
--new-datadir=$DATA_DIR"
47+
su - vcap -c "${PACKAGE_DIR}/bin/pg_upgrade \
48+
--old-bindir=${PACKAGE_DIR_OLD}/bin \
49+
--new-bindir=${PACKAGE_DIR}/bin \
50+
--old-datadir=${STORE_DIR_OLD} \
51+
--new-datadir=${STORE_DIR}"
5252

5353
echo "successfully upgraded from postgres-10"
54-
rm -rf '/var/vcap/store/postgres-10'
54+
rm -rf "${STORE_DIR_OLD}"
5555
fi
5656

57-
rm /var/vcap/store/postgres-13/fresh
57+
rm "${STORE_DIR}/fresh"
5858
fi
5959

6060
# "bpm enforces its own locking around process operations to avoid race conditions"
6161
# from docs: https://bosh.io/docs/bpm/runtime/
6262
# so postmaster.pid is stale if it still exists
6363
# remove it to prevent running into:
6464
# FATAL: lock file "postmaster.pid" already exists
65-
if [[ -f /var/vcap/store/postgres-13/postmaster.pid ]] ; then
66-
rm /var/vcap/store/postgres-13/postmaster.pid
65+
if [[ -f ${STORE_DIR}/postmaster.pid ]] ; then
66+
rm "${STORE_DIR}/postmaster.pid"
6767
fi

0 commit comments

Comments
 (0)