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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2024-10-03 21:32:55 -07:00 committed by James Valleroy
parent 2a30d64f08
commit a7911469ee
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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)