nextcloud: Restart container when dependent services are restarted

This is required because when services are restarted, their Unix domain sockets
are removed and new ones are created. The container will still be using the old
sockets and will fail to connect to the service.

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-04-15 10:50:46 -07:00 committed by James Valleroy
parent 6b046ec27d
commit 614bea4511
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 7 additions and 2 deletions

View File

@ -491,7 +491,8 @@ def is_package_manager_busy():
def podman_create(container_name: str, image_name: str, volume_name: str,
volume_path: str, volumes: dict[str, str] | None = None,
env: dict[str, str] | None = None):
env: dict[str, str] | None = None,
binds_to: list[str] | None = None):
"""Remove and recreate a podman container."""
service_stop(f'{volume_name}-volume.service')
service_stop(container_name)
@ -526,9 +527,12 @@ Options=bind
])
env_lines = '\n'.join(
[f'Environment={key}={value}' for key, value in (env or {}).items()])
bind_lines = '\n'.join(f'BindsTo={service}\nAfter={service}'
for service in (binds_to or []))
contents = f'''[Unit]
Requires=nextcloud-freedombox-volume.service
After=nextcloud-freedombox-volume.service
{bind_lines}
[Container]
AutoUpdate=registry

View File

@ -52,10 +52,11 @@ def setup():
VOLUME_NAME: '/var/www/html'
}
env = {'OVERWRITEWEBROOT': '/nextcloud'}
binds_to = ['mariadb.service', 'redis-server.service', 'slapd.service']
action_utils.podman_create(container_name=CONTAINER_NAME,
image_name=IMAGE_NAME, volume_name=VOLUME_NAME,
volume_path=str(_data_path), volumes=volumes,
env=env)
env=env, binds_to=binds_to)
action_utils.service_start(CONTAINER_NAME)
_nextcloud_wait_until_ready()