Merge branch 'bullseye' into bullseye-legacy-cleanup

This commit is contained in:
Alexandre Aubin 2021-06-07 22:09:02 +02:00 committed by GitHub
commit c32305234c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 471 additions and 17 deletions

View file

@ -181,8 +181,9 @@ ynh_package_install_from_equivs () {
# Build and install the package # Build and install the package
local TMPDIR=$(mktemp --directory) local TMPDIR=$(mktemp --directory)
# Force the compatibility level at 10, levels below are deprecated # Make sure to delete the legacy compat file
echo 10 > /usr/share/equivs/template/debian/compat # It's now handle somewhat magically through the control file
rm -f /usr/share/equivs/template/debian/compat
# Note that the cd executes into a sub shell # Note that the cd executes into a sub shell
# Create a fake deb package with equivs-build and the given control file # Create a fake deb package with equivs-build and the given control file
@ -191,7 +192,7 @@ ynh_package_install_from_equivs () {
ynh_wait_dpkg_free ynh_wait_dpkg_free
cp "$controlfile" "${TMPDIR}/control" cp "$controlfile" "${TMPDIR}/control"
(cd "$TMPDIR" (cd "$TMPDIR"
LC_ALL=C equivs-build ./control 1> /dev/null LC_ALL=C equivs-build ./control 2>&1
LC_ALL=C dpkg --force-depends --install "./${pkgname}_${pkgversion}_all.deb" 2>&1 | tee ./dpkg_log) LC_ALL=C dpkg --force-depends --install "./${pkgname}_${pkgversion}_all.deb" 2>&1 | tee ./dpkg_log)
ynh_package_install --fix-broken || \ ynh_package_install --fix-broken || \

View file

@ -206,14 +206,14 @@ ynh_restore () {
# usage: _get_archive_path ORIGIN_PATH # usage: _get_archive_path ORIGIN_PATH
_get_archive_path () { _get_archive_path () {
# For security reasons we use csv python library to read the CSV # For security reasons we use csv python library to read the CSV
python -c " python3 -c "
import sys import sys
import csv import csv
with open(sys.argv[1], 'r') as backup_file: with open(sys.argv[1], 'r') as backup_file:
backup_csv = csv.DictReader(backup_file, fieldnames=['source', 'dest']) backup_csv = csv.DictReader(backup_file, fieldnames=['source', 'dest'])
for row in backup_csv: for row in backup_csv:
if row['source']==sys.argv[2].strip('\"'): if row['source']==sys.argv[2].strip('\"'):
print row['dest'] print(row['dest'])
sys.exit(0) sys.exit(0)
raise Exception('Original path for %s not found' % sys.argv[2]) raise Exception('Original path for %s not found' % sys.argv[2])
" "${YNH_BACKUP_CSV}" "$1" " "${YNH_BACKUP_CSV}" "$1"

View file

@ -80,7 +80,7 @@ ynh_validate_ip()
[ "$family" == "4" ] || [ "$family" == "6" ] || return 1 [ "$family" == "4" ] || [ "$family" == "6" ] || return 1
python /dev/stdin << EOF python3 /dev/stdin << EOF
import socket import socket
import sys import sys
family = { "4" : socket.AF_INET, "6" : socket.AF_INET6 } family = { "4" : socket.AF_INET, "6" : socket.AF_INET6 }

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
PSQL_ROOT_PWD_FILE=/etc/yunohost/psql PSQL_ROOT_PWD_FILE=/etc/yunohost/psql
PSQL_VERSION=11 PSQL_VERSION=13
# Open a connection as a user # Open a connection as a user
# #

5
debian/control vendored
View file

@ -15,6 +15,7 @@ Depends: ${python3:Depends}, ${misc:Depends}
, python3-miniupnpc, python3-dbus, python3-jinja2 , python3-miniupnpc, python3-dbus, python3-jinja2
, python3-toml, python3-packaging, python3-publicsuffix2 , python3-toml, python3-packaging, python3-publicsuffix2
, python-is-python3 , python-is-python3
, nginx, nginx-extras (>=1.18)
, apt, apt-transport-https, apt-utils, dirmngr , apt, apt-transport-https, apt-utils, dirmngr
, php7.4-common, php7.4-fpm, php7.4-ldap, php7.4-intl , php7.4-common, php7.4-fpm, php7.4-ldap, php7.4-intl
, mariadb-server, php7.4-mysql , mariadb-server, php7.4-mysql
@ -41,10 +42,10 @@ Conflicts: iptables-persistent
, apache2 , apache2
, bind9 , bind9
, nginx-extras (>= 1.19) , nginx-extras (>= 1.19)
, openssl (>= 1.1.1j-2) , openssl (>= 1.1.1l-1)
, slapd (>= 2.4.58) , slapd (>= 2.4.58)
, dovecot-core (>= 1:2.3.14) , dovecot-core (>= 1:2.3.14)
, redis-server (>= 5:6.0.12) , redis-server (>= 5:6.1)
, fail2ban (>= 0.11.3) , fail2ban (>= 0.11.3)
, iptables (>= 1.8.8) , iptables (>= 1.8.8)
Description: manageable and configured self-hosting server Description: manageable and configured self-hosting server

View file

@ -419,10 +419,29 @@
"mail_unavailable": "This e-mail address is reserved and shall be automatically allocated to the very first user", "mail_unavailable": "This e-mail address is reserved and shall be automatically allocated to the very first user",
"main_domain_change_failed": "Unable to change the main domain", "main_domain_change_failed": "Unable to change the main domain",
"main_domain_changed": "The main domain has been changed", "main_domain_changed": "The main domain has been changed",
"migration_description_0021_migrate_to_bullseye": "Upgrade the system to Debian Bullseye and YunoHost 11.x",
"migration_description_0022_php73_to_php74_pools": "Migrate php7.3-fpm 'pool' conf files to php7.4",
"migration_description_0023_postgresql_11_to_13": "Migrate databases from PostgreSQL 11 to 13",
"migration_ldap_backup_before_migration": "Creating a backup of LDAP database and apps settings prior to the actual migration.", "migration_ldap_backup_before_migration": "Creating a backup of LDAP database and apps settings prior to the actual migration.",
"migration_ldap_can_not_backup_before_migration": "The backup of the system could not be completed before the migration failed. Error: {error:s}", "migration_ldap_can_not_backup_before_migration": "The backup of the system could not be completed before the migration failed. Error: {error:s}",
"migration_ldap_migration_failed_trying_to_rollback": "Could not migrate... trying to roll back the system.", "migration_ldap_migration_failed_trying_to_rollback": "Could not migrate... trying to roll back the system.",
"migration_ldap_rollback_success": "System rolled back.", "migration_ldap_rollback_success": "System rolled back.",
"migration_0021_start" : "Starting migration to Bullseye",
"migration_0021_patching_sources_list": "Patching the sources.lists...",
"migration_0021_main_upgrade": "Starting main upgrade...",
"migration_0021_still_on_buster_after_main_upgrade": "Something went wrong during the main upgrade, the system appears to still be on Debian Buster",
"migration_0021_yunohost_upgrade" : "Starting YunoHost core upgrade...",
"migration_0021_not_buster" : "The current Debian distribution is not Buster!",
"migration_0021_not_enough_free_space" : "Free space is pretty low in /var/! You should have at least 1GB free to run this migration.",
"migration_0021_system_not_fully_up_to_date": "Your system is not fully up-to-date. Please perform a regular upgrade before running the migration to Bullseye.",
"migration_0021_general_warning": "Please note that this migration is a delicate operation. The YunoHost team did its best to review and test it, but the migration might still break parts of the system or its apps.\n\nTherefore, it is recommended to:\n - Perform a backup of any critical data or app. More info on https://yunohost.org/backup;\n - Be patient after launching the migration: Depending on your Internet connection and hardware, it might take up to a few hours for everything to upgrade.",
"migration_0021_problematic_apps_warning": "Please note that the following possibly problematic installed apps were detected. It looks like those were not installed from the YunoHost app catalog, or are not flagged as 'working'. Consequently, it cannot be guaranteed that they will still work after the upgrade: {problematic_apps}",
"migration_0021_modified_files": "Please note that the following files were found to be manually modified and might be overwritten following the upgrade: {manually_modified_files}",
"migration_0021_cleaning_up": "Cleaning up cache and packages not useful anymore...",
"migration_0021_patch_yunohost_conflicts": "Applying patch to workaround conflict issue...",
"migration_0023_postgresql_11_not_installed": "PostgreSQL was not installed on your system. Nothing to do.",
"migration_0023_postgresql_13_not_installed": "PostgreSQL 11 is installed, but not postgresql 13!? Something weird might have happened on your system :(...",
"migration_0023_not_enough_space": "Make sufficient space available in {path} to run the migration.",
"migrations_already_ran": "Those migrations are already done: {ids}", "migrations_already_ran": "Those migrations are already done: {ids}",
"migrations_cant_reach_migration_file": "Could not access migrations files at the path '%s'", "migrations_cant_reach_migration_file": "Could not access migrations files at the path '%s'",
"migrations_dependencies_not_satisfied": "Run these migrations: '{dependencies_id}', before migration {id}.", "migrations_dependencies_not_satisfied": "Run these migrations: '{dependencies_id}', before migration {id}.",

View file

@ -3386,14 +3386,23 @@ LEGACY_PHP_VERSION_REPLACEMENTS = [
("php5", "php7.4"), ("php5", "php7.4"),
("php7.0", "php7.4"), ("php7.0", "php7.4"),
("php7.3", "php7.4"), ("php7.3", "php7.4"),
('YNH_PHP_VERSION="7.3"', 'YNH_PHP_VERSION="7.4"'),
( (
'phpversion="${phpversion:-7.0}"', 'phpversion="${phpversion:-7.0}"',
'phpversion="${phpversion:-7.4}"', 'phpversion="${phpversion:-7.4}"',
), # Many helpers like the composer ones use 7.0 by default ... ), # Many helpers like the composer ones use 7.0 by default ...
(
'phpversion="${phpversion:-7.3}"',
'phpversion="${phpversion:-7.4}"',
), # Many helpers like the composer ones use 7.0 by default ...
( (
'"$phpversion" == "7.0"', '"$phpversion" == "7.0"',
'$(bc <<< "$phpversion >= 7.4") -eq 1', '$(bc <<< "$phpversion >= 7.4") -eq 1',
), # patch ynh_install_php to refuse installing/removing php <= 7.3 ), # patch ynh_install_php to refuse installing/removing php <= 7.3
(
'"$phpversion" == "7.3"',
'$(bc <<< "$phpversion >= 7.4") -eq 1',
), # patch ynh_install_php to refuse installing/removing php <= 7.3
] ]
@ -3428,15 +3437,15 @@ def _patch_legacy_php_versions_in_settings(app_folder):
settings = read_yaml(os.path.join(app_folder, "settings.yml")) settings = read_yaml(os.path.join(app_folder, "settings.yml"))
if settings.get("fpm_config_dir") == "/etc/php/7.0/fpm": if settings.get("fpm_config_dir") in ["/etc/php/7.0/fpm", "/etc/php/7.3/fpm"]:
settings["fpm_config_dir"] = "/etc/php/7.4/fpm" settings["fpm_config_dir"] = "/etc/php/7.4/fpm"
if settings.get("fpm_service") == "php7.0-fpm": if settings.get("fpm_service") in ["php7.0-fpm", "php7.3-fpm"]:
settings["fpm_service"] = "php7.4-fpm" settings["fpm_service"] = "php7.4-fpm"
if settings.get("phpversion") == "7.0": if settings.get("phpversion") in ["7.0", "7.3"]:
settings["phpversion"] = "7.4" settings["phpversion"] = "7.4"
# We delete these checksums otherwise the file will appear as manually modified # We delete these checksums otherwise the file will appear as manually modified
list_to_remove = ["checksum__etc_php_7.0_fpm_pool", "checksum__etc_nginx_conf.d"] list_to_remove = ["checksum__etc_php_7.3_fpm_pool", "checksum__etc_php_7.0_fpm_pool", "checksum__etc_nginx_conf.d"]
settings = { settings = {
k: v k: v
for k, v in settings.items() for k, v in settings.items()

View file

@ -860,9 +860,13 @@ class RestoreManager:
# FIXME this way to get the info is not compatible with copy or custom # FIXME this way to get the info is not compatible with copy or custom
# backup methods # backup methods
self.info = backup_info(name, with_details=True) self.info = backup_info(name, with_details=True)
if not self.info["from_yunohost_version"] or version.parse(
self.info["from_yunohost_version"] from_version = self.info.get("from_yunohost_version", "")
) < version.parse("3.8.0"): # Remove any '~foobar' in the version ... c.f ~alpha, ~beta version during
# early dev for next debian version
from_version = re.sub(r'~\w+', '', from_version)
if not from_version or version.parse(from_version) < version.parse("3.8.0"):
raise YunohostValidationError("restore_backup_too_old") raise YunohostValidationError("restore_backup_too_old")
self.archive_path = self.info["path"] self.archive_path = self.info["path"]

View file

@ -0,0 +1,255 @@
import glob
import os
from moulinette import m18n
from yunohost.utils.error import YunohostError
from moulinette.utils.log import getActionLogger
from moulinette.utils.process import check_output, call_async_output
from moulinette.utils.filesystem import read_file
from yunohost.tools import Migration, tools_update, tools_upgrade
from yunohost.app import unstable_apps
from yunohost.regenconf import manually_modified_files
from yunohost.utils.filesystem import free_space_in_directory
from yunohost.utils.packages import (
get_ynh_package_version,
_list_upgradable_apt_packages,
)
logger = getActionLogger("yunohost.migration")
N_CURRENT_DEBIAN = 10
N_CURRENT_YUNOHOST = 4
N_NEXT_DEBAN = 11
N_NEXT_YUNOHOST = 11
class MyMigration(Migration):
"Upgrade the system to Debian Bullseye and Yunohost 11.x"
mode = "manual"
def run(self):
self.check_assertions()
logger.info(m18n.n("migration_0021_start"))
#
# Patch sources.list
#
logger.info(m18n.n("migration_0021_patching_sources_list"))
self.patch_apt_sources_list()
tools_update(target="system")
# Tell libc6 it's okay to restart system stuff during the upgrade
os.system(
"echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections"
)
# Don't send an email to root about the postgresql migration. It should be handled automatically after.
os.system(
"echo 'postgresql-common postgresql-common/obsolete-major seen true' | debconf-set-selections"
)
#
# Patch yunohost conflicts
#
logger.info(m18n.n("migration_0021_patch_yunohost_conflicts"))
self.patch_yunohost_conflicts()
#
# Main upgrade
#
logger.info(m18n.n("migration_0021_main_upgrade"))
apps_packages = self.get_apps_equivs_packages()
self.hold(apps_packages)
tools_upgrade(target="system", allow_yunohost_upgrade=False)
if self.debian_major_version() == N_CURRENT_DEBIAN:
raise YunohostError("migration_0021_still_on_buster_after_main_upgrade")
# Clean the mess
logger.info(m18n.n("migration_0021_cleaning_up"))
os.system("apt autoremove --assume-yes")
os.system("apt clean --assume-yes")
#
# Yunohost upgrade
#
logger.info(m18n.n("migration_0021_yunohost_upgrade"))
self.unhold(apps_packages)
tools_upgrade(target="system")
def debian_major_version(self):
# The python module "platform" and lsb_release are not reliable because
# on some setup, they may still return Release=9 even after upgrading to
# buster ... (Apparently this is related to OVH overriding some stuff
# with /etc/lsb-release for instance -_-)
# Instead, we rely on /etc/os-release which should be the raw info from
# the distribution...
return int(
check_output(
"grep VERSION_ID /etc/os-release | head -n 1 | tr '\"' ' ' | cut -d ' ' -f2"
)
)
def yunohost_major_version(self):
return int(get_ynh_package_version("yunohost")["version"].split(".")[0])
def check_assertions(self):
# Be on buster (10.x) and yunohost 4.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() == N_CURRENT_DEBIAN
and not self.yunohost_major_version() == N_CURRENT_YUNOHOST
):
raise YunohostError("migration_0021_not_buster")
# Have > 1 Go free space on /var/ ?
if free_space_in_directory("/var/") / (1024 ** 3) < 1.0:
raise YunohostError("migration_0021_not_enough_free_space")
# Check system is up to date
# (but we don't if 'bullseye' is already in the sources.list ...
# which means maybe a previous upgrade crashed and we're re-running it)
if " bullseye " not in read_file("/etc/apt/sources.list"):
tools_update(target="system")
upgradable_system_packages = list(_list_upgradable_apt_packages())
if upgradable_system_packages:
raise YunohostError("migration_0021_system_not_fully_up_to_date")
@property
def disclaimer(self):
# Avoid having a super long disclaimer + uncessary check if we ain't
# on buster / yunohost 4.x anymore
# NB : we do both check to cover situations where the upgrade crashed
# in the middle and debian version could be >= 10.x but yunohost package
# would still be in 4.x...
if (
not self.debian_major_version() == N_CURRENT_DEBIAN
and not self.yunohost_major_version() == N_CURRENT_YUNOHOST
):
return None
# Get list of problematic apps ? I.e. not official or community+working
problematic_apps = unstable_apps()
problematic_apps = "".join(["\n - " + app for app in problematic_apps])
# Manually modified files ? (c.f. yunohost service regen-conf)
modified_files = manually_modified_files()
modified_files = "".join(["\n - " + f for f in modified_files])
message = m18n.n("migration_0021_general_warning")
# FIXME: re-enable this message with updated topic link once we release the migration as stable
#message = (
# "N.B.: This migration has been tested by the community over the last few months but has only been declared stable recently. If your server hosts critical services and if you are not too confident with debugging possible issues, we recommend you to wait a little bit more while we gather more feedback and polish things up. If on the other hand you are relatively confident with debugging small issues that may arise, you are encouraged to run this migration ;)! You can read about remaining known issues and feedback from the community here: https://forum.yunohost.org/t/12195\n\n"
# + message
#)
if problematic_apps:
message += "\n\n" + m18n.n(
"migration_0021_problematic_apps_warning",
problematic_apps=problematic_apps,
)
if modified_files:
message += "\n\n" + m18n.n(
"migration_0021_modified_files", manually_modified_files=modified_files
)
return message
def patch_apt_sources_list(self):
sources_list = glob.glob("/etc/apt/sources.list.d/*.list")
sources_list.append("/etc/apt/sources.list")
# This :
# - replace single 'buster' occurence by 'bulleye'
# - comments lines containing "backports"
# - replace 'buster/updates' by 'bullseye/updates' (or same with -)
# Special note about the security suite:
# https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html#security-archive
for f in sources_list:
command = (
f"sed -i {f} "
"-e 's@ buster @ bullseye @g' "
"-e '/backports/ s@^#*@#@' "
"-e 's@ buster/updates @ bullseye-security @g' "
"-e 's@ buster-@ bullseye-@g' "
)
os.system(command)
def get_apps_equivs_packages(self):
command = (
"dpkg --get-selections"
" | grep -v deinstall"
" | awk '{print $1}'"
" | { grep 'ynh-deps$' || true; }"
)
output = check_output(command)
return output.split("\n") if output else []
def hold(self, packages):
for package in packages:
os.system("apt-mark hold {}".format(package))
def unhold(self, packages):
for package in packages:
os.system("apt-mark unhold {}".format(package))
def apt_install(self, cmd):
def is_relevant(line):
return "Reading database ..." not in line.rstrip()
callbacks = (
lambda l: logger.info("+ " + l.rstrip() + "\r")
if is_relevant(l)
else logger.debug(l.rstrip() + "\r"),
lambda l: logger.warning(l.rstrip()),
)
cmd = (
"LC_ALL=C DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none apt install --quiet -o=Dpkg::Use-Pty=0 --fix-broken --assume-yes "
+ cmd
)
logger.debug("Running: %s" % cmd)
call_async_output(cmd, callbacks, shell=True)
def patch_yunohost_conflicts(self):
#
# This is a super dirty hack to remove the conflicts from yunohost's debian/control file
# Those conflicts are there to prevent mistakenly upgrading critical packages
# such as dovecot, postfix, nginx, openssl, etc... usually related to mistakenly
# using backports etc.
#
# The hack consists in savagely removing the conflicts directly in /var/lib/dpkg/status
#
# We only patch the conflict if we're on yunohost 4.x
if self.yunohost_major_version() != N_CURRENT_YUNOHOST:
return
conflicts = check_output("dpkg-query -s yunohost | grep '^Conflicts:'").strip()
if conflicts:
# We want to keep conflicting with apache/bind9 tho
new_conflicts = "Conflicts: apache2, bind9"
command = f"sed -i /var/lib/dpkg/status -e 's@{conflicts}@{new_conflicts}@g'"
logger.debug(f"Running: {command}")
os.system(command)

View file

@ -0,0 +1,83 @@
import os
import glob
from shutil import copy2
from moulinette.utils.log import getActionLogger
from yunohost.app import _is_installed, _patch_legacy_php_versions_in_settings
from yunohost.tools import Migration
from yunohost.service import _run_service_command
logger = getActionLogger("yunohost.migration")
OLDPHP_POOLS = "/etc/php/7.3/fpm/pool.d"
NEWPHP_POOLS = "/etc/php/7.4/fpm/pool.d"
OLDPHP_SOCKETS_PREFIX = "/run/php/php7.3-fpm"
NEWPHP_SOCKETS_PREFIX = "/run/php/php7.4-fpm"
MIGRATION_COMMENT = (
"; YunoHost note : this file was automatically moved from {}".format(OLDPHP_POOLS)
)
class MyMigration(Migration):
"Migrate php7.3-fpm 'pool' conf files to php7.4"
dependencies = ["migrate_to_bullseye"]
def run(self):
# Get list of php7.3 pool files
oldphp_pool_files = glob.glob("{}/*.conf".format(OLDPHP_POOLS))
# Keep only basenames
oldphp_pool_files = [os.path.basename(f) for f in oldphp_pool_files]
# Ignore the "www.conf" (default stuff, probably don't want to touch it ?)
oldphp_pool_files = [f for f in oldphp_pool_files if f != "www.conf"]
for f in oldphp_pool_files:
# Copy the files to the php7.4 pool
src = "{}/{}".format(OLDPHP_POOLS, f)
dest = "{}/{}".format(NEWPHP_POOLS, f)
copy2(src, dest)
# Replace the socket prefix if it's found
c = "sed -i -e 's@{}@{}@g' {}".format(
OLDPHP_SOCKETS_PREFIX, NEWPHP_SOCKETS_PREFIX, dest
)
os.system(c)
# Also add a comment that it was automatically moved from php7.3
# (for human traceability and backward migration)
c = "sed -i '1i {}' {}".format(MIGRATION_COMMENT, dest)
os.system(c)
app_id = os.path.basename(f)[: -len(".conf")]
if _is_installed(app_id):
_patch_legacy_php_versions_in_settings(
"/etc/yunohost/apps/%s/" % app_id
)
nginx_conf_files = glob.glob("/etc/nginx/conf.d/*.d/%s.conf" % app_id)
for f in nginx_conf_files:
# Replace the socket prefix if it's found
c = "sed -i -e 's@{}@{}@g' {}".format(
OLDPHP_SOCKETS_PREFIX, NEWPHP_SOCKETS_PREFIX, f
)
os.system(c)
os.system(
"rm /etc/logrotate.d/php7.3-fpm"
) # We remove this otherwise the logrotate cron will be unhappy
# Reload/restart the php pools
_run_service_command("restart", "php7.4-fpm")
_run_service_command("enable", "php7.4-fpm")
os.system("systemctl stop php7.3-fpm")
os.system("systemctl disable php7.3-fpm")
# Reload nginx
_run_service_command("reload", "nginx")

View file

@ -0,0 +1,82 @@
import subprocess
from moulinette import m18n
from yunohost.utils.error import YunohostError, YunohostValidationError
from moulinette.utils.log import getActionLogger
from yunohost.tools import Migration
from yunohost.utils.filesystem import free_space_in_directory, space_used_by_directory
logger = getActionLogger("yunohost.migration")
class MyMigration(Migration):
"Migrate DBs from Postgresql 11 to 13 after migrating to Bullseye"
dependencies = ["migrate_to_bullseye"]
def run(self):
if not self.package_is_installed("postgresql-11"):
logger.warning(m18n.n("migration_0023_postgresql_11_not_installed"))
return
if not self.package_is_installed("postgresql-13"):
raise YunohostValidationError("migration_0023_postgresql_13_not_installed")
# Make sure there's a 11 cluster
try:
self.runcmd("pg_lsclusters | grep -q '^11 '")
except Exception:
logger.warning(
"It looks like there's not active 11 cluster, so probably don't need to run this migration"
)
return
if not space_used_by_directory(
"/var/lib/postgresql/11"
) > free_space_in_directory("/var/lib/postgresql"):
raise YunohostValidationError(
"migration_0023_not_enough_space", path="/var/lib/postgresql/"
)
self.runcmd("systemctl stop postgresql")
self.runcmd(
"LC_ALL=C pg_dropcluster --stop 13 main || true"
) # We do not trigger an exception if the command fails because that probably means cluster 13 doesn't exists, which is fine because it's created during the pg_upgradecluster)
self.runcmd("LC_ALL=C pg_upgradecluster -m upgrade 11 main")
self.runcmd("LC_ALL=C pg_dropcluster --stop 11 main")
self.runcmd("systemctl start postgresql")
def package_is_installed(self, package_name):
(returncode, out, err) = self.runcmd(
"dpkg --list | grep '^ii ' | grep -q -w {}".format(package_name),
raise_on_errors=False,
)
return returncode == 0
def runcmd(self, cmd, raise_on_errors=True):
logger.debug("Running command: " + cmd)
p = subprocess.Popen(
cmd,
shell=True,
executable="/bin/bash",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, err = p.communicate()
returncode = p.returncode
if raise_on_errors and returncode != 0:
raise YunohostError(
"Failed to run command '{}'.\nreturncode: {}\nstdout:\n{}\nstderr:\n{}\n".format(
cmd, returncode, out, err
)
)
out = out.strip().split(b"\n")
return (returncode, out, err)

View file

@ -35,7 +35,7 @@ trap cleanup EXIT SIGINT
HTTPSERVER_DIR=$(mktemp -d) HTTPSERVER_DIR=$(mktemp -d)
HTTPSERVER_PORT=1312 HTTPSERVER_PORT=1312
pushd "$HTTPSERVER_DIR" >/dev/null pushd "$HTTPSERVER_DIR" >/dev/null
python -m SimpleHTTPServer $HTTPSERVER_PORT &>/dev/null & python3 -m http.server $HTTPSERVER_PORT --bind 127.0.0.1 &>/dev/null &
HTTPSERVER="$!" HTTPSERVER="$!"
popd >/dev/null popd >/dev/null