def run(self): if not self.package_is_installed("postgresql-9.6"): logger.warning( m18n.n("migration_0017_postgresql_96_not_installed")) return if not self.package_is_installed("postgresql-11"): raise YunohostError("migration_0017_postgresql_11_not_installed") # Make sure there's a 9.6 cluster try: self.runcmd("pg_lsclusters | grep -q '^9.6 '") except Exception: logger.warning( "It looks like there's not active 9.6 cluster, so probably don't need to run this migration" ) return if not space_used_by_directory( "/var/lib/postgresql/9.6") > free_space_in_directory( "/var/lib/postgresql"): raise YunohostError("migration_0017_not_enough_space", path="/var/lib/postgresql/") self.runcmd("systemctl stop postgresql") self.runcmd( "LC_ALL=C pg_dropcluster --stop 11 main || true" ) # We do not trigger an exception if the command fails because that probably means cluster 11 doesn't exists, which is fine because it's created during the pg_upgradecluster) self.runcmd("LC_ALL=C pg_upgradecluster -m upgrade 9.6 main") self.runcmd("LC_ALL=C pg_dropcluster --stop 9.6 main") self.runcmd("systemctl start postgresql")
def check_assertions(self): # Be on stretch (9.x) and yunohost 3.x # NB : we do both check to cover situations where the upgrade crashed # in the middle and debian version could be > 9.x but yunohost package # would still be in 3.x... if not self.debian_major_version() == 9 \ and not self.yunohost_major_version() == 3: raise YunohostError("migration_0015_not_stretch") # Have > 1 Go free space on /var/ ? if free_space_in_directory("/var/") / (1024**3) < 1.0: raise YunohostError("migration_0015_not_enough_free_space") # Check system is up to date # (but we don't if 'stretch' is already in the sources.list ... # which means maybe a previous upgrade crashed and we're re-running it) if " buster " not in read_file("/etc/apt/sources.list"): tools_update(system=True) upgradable_system_packages = list(_list_upgradable_apt_packages()) if upgradable_system_packages: raise YunohostError( "migration_0015_system_not_fully_up_to_date")