#!/usr/bin/env bash set -euo pipefail if [ "$EUID" -ne 0 ]; then echo "Error: This script must be run as root" >&2 exit 1 fi # Force a known locale; some OS X terminals set an invalid LC_CTYPE # which crashes pg_upgradecluster export LC_ALL=C.UTF-8 export LANG=C.UTF-8 export LANGUAGE=C.UTF-8 LATEST_SUPPORTED_VERSION=15 UPGRADE_TO=${1:-$LATEST_SUPPORTED_VERSION} 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 if [[ "$UPGRADE_TO" -lt "$UPGRADE_FROM" ]]; then echo "Refusing to downgrade PostgreSQL $UPGRADE_FROM to $UPGRADE_TO!" exit 1 fi if [[ "$UPGRADE_TO" -gt "$LATEST_SUPPORTED_VERSION" ]]; then echo "This version of Zulip does not support PostgreSQL $UPGRADE_TO." echo "You may need to upgrade Zulip before you can upgrade to PostgreSQL $UPGRADE_TO." exit 1 fi # Verify that the version in /etc/zulip/zulip.conf is the version that # Django actually stores its data in. We can only do that if the # database server is on the same host as the application server. if [ -d /home/zulip/deployments/current ]; then DATA_IS_IN=$(su zulip -c '/home/zulip/deployments/current/manage.py shell -c "from django.db import connection; print(int(connection.cursor().connection.server_version/10000))"') if [ "$UPGRADE_FROM" != "$DATA_IS_IN" ]; then cat <>>>> pg_upgradecluster succeeded, but post-upgrade scripts path could not" echo " be parsed out! Please read the pg_upgradecluster output to understand" echo " the current status of your cluster:" echo " $UPGRADE_LOG" echo " and report this bug with the PostgreSQL $UPGRADE_FROM -> $UPGRADE_TO upgrade to:" echo " https://github.com/zulip/zulip/issues" echo echo fi