-
Notifications
You must be signed in to change notification settings - Fork 38
/
pre-start.sh.erb
61 lines (50 loc) · 1.43 KB
/
pre-start.sh.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash -exu
set +u
source /var/vcap/packages/postgres-common/utils.sh
set -u
source /var/vcap/jobs/postgres/bin/pgconfig.sh
source /var/vcap/jobs/postgres/bin/utils.sh
function upgrade(){
if [ -d $DATA_DIR -a -f $POSTGRES_UPGRADE_LOCK ]; then
echo "FAIL: DB upgrade stopped in the middle, manual intervention required, quitting..."
exit 1
fi
if [ -d "${DATA_DIR_OLD}" -a -f "${DATA_DIR_OLD}/postgresql.conf" ]; then
# UPGRADING
if is_major; then
run_major_upgrade
else
run_minor_upgrade
fi
else
init_data_dir
fi
}
function main() {
echo "Checking PostgreSQL is stopped"
check_pidfile "${PIDFILE}" 30
mkdir -p "${PG_STORE_DIR}"
chown -R vcap:vcap "${PG_STORE_DIR}"
chmod 700 "${PG_STORE_DIR}"
for dir in ${pgversion_older} ${pgversion_old} ${pgversion_current} postgres-previous; do
if [[ -d "${STORE_DIR}/${dir}" ]]; then
if [[ -f "${STORE_DIR}/${dir}/postgresql.conf" ]]; then
mv "${STORE_DIR}/${dir}" "${PG_STORE_DIR}"
chown -R vcap:vcap "${PG_STORE_DIR}/${dir}"
chmod 700 "${PG_STORE_DIR}/${dir}"
else
rm -r ${STORE_DIR}/${dir}
fi
fi
done
mkdir -p "${LOG_DIR}"
chown -R vcap:vcap "${LOG_DIR}"
mkdir -p "${RUN_DIR}"
chown -R vcap:vcap "${RUN_DIR}"
PG_CERTS_DIR=${JOB_DIR}/config/certificates
chmod -R 600 ${PG_CERTS_DIR}/*
chown -R vcap:vcap ${PG_CERTS_DIR}/*
sysctl -w "kernel.shmmax=284934144"
}
main
upgrade