-
Notifications
You must be signed in to change notification settings - Fork 36
/
pre-start.sh.erb
68 lines (54 loc) · 1.67 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
61
62
63
64
65
66
67
#!/bin/bash -eu
pidnum=$$
pname=$(basename $0)
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
tee_output_to_sys_log "${LOG_DIR}" "${pname}" "${LOG_FORMAT}" "${pname}.stdout.log" "${pname}.stderr.log" "${pidnum}"
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
if [ ${pgversion_upgrade_from} != ${pgversion_current} ]; then
# UPGRADING
if is_major; then
run_major_upgrade
else
run_minor_upgrade
fi
fi
else
init_data_dir
fi
echo ${pgversion_current} > ${VERSION_FILE}
chown -R vcap:vcap "${VERSION_FILE}"
chmod 700 "${VERSION_FILE}"
}
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}"
if [ ! -f ${VERSION_FILE} ]; then
existing_data_dirs=$(compgen -G "${PG_STORE_DIR}/postgres-*" || echo "")
if [ -n "${existing_data_dirs}" ]; then
echo "Found existing data dirs that we cannot upgrade from in this release. Upgrade to and older version first."
exit 1
fi
fi
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