diff --git a/puppet/zulip/manifests/base.pp b/puppet/zulip/manifests/base.pp index 7e4a29d33e..dd9e43557f 100644 --- a/puppet/zulip/manifests/base.pp +++ b/puppet/zulip/manifests/base.pp @@ -56,20 +56,7 @@ class zulip::base { } package { $base_packages: ensure => 'installed' } - $postgres_version = zulipconf('postgresql', 'version', $release_name ? { - 'wheezy' => '9.1', - 'jessie' => '9.4', - 'stretch' => '9.6', - 'buster' => '11', - 'precise' => '9.1', - 'trusty' => '9.3', - 'vivid' => '9.4', - 'wily' => '9.4', - 'xenial' => '9.5', - 'bionic' => '10', - 'CentOS7' => '10', - 'focal' => '12', - }) + $postgres_version = zulipconf('postgresql', 'version', undef) $normal_queues = [ 'deferred_work', diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index 978a179f5e..0e154f6d25 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -12,6 +12,10 @@ import os import subprocess import sys import time +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from typing import NoReturn os.environ["PYTHONUNBUFFERED"] = "y" @@ -27,6 +31,7 @@ from scripts.lib.zulip_tools import ( get_config, get_config_file, parse_os_release, + set_config, su_to_zulip, ) @@ -36,6 +41,17 @@ logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s upgrade-zulip-stage-2: %(message)s", level=logging.INFO) + +def error_desupported_os(vendor: str, os_version: str) -> "NoReturn": + # Link to documentation for how to correctly upgrade the OS. + logging.critical("Unsupported platform: %s %s", vendor, os_version) + logging.info("Sorry! The support for your OS has been discontinued.\n" + "Please upgrade your OS to a supported release first.\n" + "See https://zulip.readthedocs.io/en/latest/production/" + "upgrade-or-modify.html#upgrading-the-operating-system") + sys.exit(1) + + # Do not upgrade on unsupported OS versions. UNSUPPORTED_DISTROS = [ ('ubuntu', '14.04'), @@ -47,13 +63,7 @@ vendor = distro_info['ID'] os_version = distro_info['VERSION_ID'] if (vendor, os_version) in UNSUPPORTED_DISTROS: - # Link to documentation for how to correctly upgrade the OS. - logging.critical("Unsupported platform: %s %s", vendor, os_version) - logging.info("Sorry! The support for your OS has been discontinued.\n" - "Please upgrade your OS to a supported release first.\n" - "See https://zulip.readthedocs.io/en/latest/production/" - "upgrade-or-modify.html#upgrading-the-operating-system") - sys.exit(1) + error_desupported_os(vendor, os_version) # make sure we have appropriate file permissions os.umask(0o22) @@ -96,6 +106,23 @@ def shutdown_server() -> None: preexec_fn=su_to_zulip) IS_SERVER_UP = False +# postgresql.version is required for database servers, but wasn't +# previously; fill it in based on what the OS provides. +if os.path.exists('/etc/init.d/postgresql'): + postgres_version = get_config(config_file, 'postgresql', 'version') + if not postgres_version: + default_postgres_version = { + ('debian', '10'): '11', + ('ubuntu', '18.04'): '10', + ('ubuntu', '20.04'): '12', + ('centos', '7'): '11', + } + if (vendor, os_version) in default_postgres_version: + postgres_version = default_postgres_version[(vendor, os_version)] + else: + error_desupported_os(vendor, os_version) + set_config(config_file, 'postgresql', 'version', postgres_version) + if glob.glob("/usr/share/postgresql/*/extension/tsearch_extras.control"): # Remove legacy tsearch_extras package references subprocess.check_call([ diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index ef4e88a6a5..069e30138d 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -489,6 +489,16 @@ def get_config( return config_file.get(section, key) return default_value +def set_config( + config_file: configparser.RawConfigParser, + section: str, + key: str, + value: str, +) -> None: + if not config_file.has_section(section): + config_file.add_section(section) + config_file.set(section, key, value) + def get_config_file() -> configparser.RawConfigParser: config_file = configparser.RawConfigParser() config_file.read("/etc/zulip/zulip.conf")