2020-06-26 23:32:36 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
echo "Error: This script must be run as root" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
UPGRADE_TO=${1:-12}
|
|
|
|
UPGRADE_FROM=$(crudini --get /etc/zulip/zulip.conf postgresql version)
|
|
|
|
ZULIP_PATH="$(dirname "$0")/../.."
|
|
|
|
|
|
|
|
if [ "$UPGRADE_TO" = "$UPGRADE_FROM" ]; then
|
|
|
|
echo "Already running PostgreSQL $UPGRADE_TO!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
"$ZULIP_PATH"/scripts/lib/setup-apt-repo
|
|
|
|
apt-get install -y "postgresql-$UPGRADE_TO"
|
|
|
|
if pg_lsclusters -h | grep -qE "^$UPGRADE_TO\s+main\b"; then
|
|
|
|
pg_dropcluster "$UPGRADE_TO" main --stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Work around `systemctl stop postgresql` being asynchronous, since
|
2020-06-27 05:28:59 +02:00
|
|
|
# the pg_upgradecluster command fails if it is still running
|
2020-06-26 23:32:36 +02:00
|
|
|
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=759725
|
2020-06-27 05:28:59 +02:00
|
|
|
pg_ctlcluster "$UPGRADE_FROM" main stop
|
2020-07-07 01:39:37 +02:00
|
|
|
|
|
|
|
(
|
|
|
|
# Two-stage application of puppet; we apply the bare-bones
|
|
|
|
# postgresql configuration first, so that FTS will be configured
|
|
|
|
# prior to the pg_upgradecluster.
|
|
|
|
TEMP_CONF_DIR=$(mktemp -d)
|
|
|
|
cp /etc/zulip/zulip.conf "$TEMP_CONF_DIR"
|
|
|
|
ZULIP_CONF="${TEMP_CONF_DIR}/zulip.conf"
|
|
|
|
crudini --set "$ZULIP_CONF" postgresql version "$UPGRADE_TO"
|
|
|
|
crudini --set "$ZULIP_CONF" machine puppet_classes zulip::base,zulip::postgres_appdb_base
|
|
|
|
touch "/usr/share/postgresql/$UPGRADE_TO/pgroonga_setup.sql.applied"
|
|
|
|
|
|
|
|
"$ZULIP_PATH"/scripts/zulip-puppet-apply -f --config "$ZULIP_CONF"
|
|
|
|
rm -rf "$TEMP_CONF_DIR"
|
|
|
|
)
|
|
|
|
|
2020-06-26 23:32:36 +02:00
|
|
|
pg_upgradecluster "$UPGRADE_FROM" main
|
|
|
|
|
|
|
|
crudini --set /etc/zulip/zulip.conf postgresql version "$UPGRADE_TO"
|
|
|
|
"$ZULIP_PATH"/scripts/zulip-puppet-apply -f
|
|
|
|
|
2020-06-27 05:28:59 +02:00
|
|
|
service memcached restart
|
2020-06-26 23:32:36 +02:00
|
|
|
|
|
|
|
pg_dropcluster "$UPGRADE_FROM" main
|
|
|
|
apt remove -y "postgresql-$UPGRADE_FROM"
|