From a7911469eed776bdbe7b02a8a208b94143e22f86 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 3 Oct 2024 21:32:55 -0700 Subject: [PATCH] nextcloud: During upgrade wait properly for upgrade to complete - Before rerunning setup operations. Tests: - Install version 28-fpm (one version older than the current stable). Then change it stable-fpm and increment the nextcloud app version at the same time. Start the service. Notice that nextcloud app setup is rerun, container will be updated by podman to newer version. Setup completes successfully with the patch but fails arbitrarily otherwise as the setup process does not wait for the upgrade to complete and tries to prematurely re-run setup operations. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/nextcloud/privileged.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/plinth/modules/nextcloud/privileged.py b/plinth/modules/nextcloud/privileged.py index 3cdacf18c..1ef8c707b 100644 --- a/plinth/modules/nextcloud/privileged.py +++ b/plinth/modules/nextcloud/privileged.py @@ -201,12 +201,33 @@ def _set_database_privileges(db_password: str): def _nextcloud_wait_until_ready(): """Wait for Nextcloud container to get ready.""" + + def _versions_match(): + """Return if versions in shipped and runtime directories match. + + Nextcloud container ships with source in /usr/source/nextcloud. This is + copied to /var/www/html/ when there is a mismatch between their + version.php. The last step in the coping process is the copy of + version.php file itself. + """ + try: + source_version = '/usr/src/nextcloud/version.php' + runtime_version = '/var/www/html/version.php' + _run_in_container('diff', source_version, runtime_version) + return True + except subprocess.CalledProcessError: + return False + # Nextcloud copies sources from /usr/src/nextcloud to /var/www/html inside # the container. Nextcloud is served from the latter location. This happens - # on first run of the container and when upgrade happen. + # on first run of the container and when upgrade happen. Checking for + # existence of version.php is easy and works for first install. For + # upgrades, we must wait until source is copied to the runtime directory. + # The last file to be copied the version.php. Only after this is checking + # for the lock file below meaningful. start_time = time.time() while time.time() < start_time + 300: - if (_data_path / 'version.php').exists(): + if (_data_path / 'version.php').exists() and _versions_match(): break time.sleep(1)