From 2b93392b5945deb9303c5e30660e31613017ff2e Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Tue, 1 Oct 2024 22:32:35 +0500 Subject: [PATCH] Gracefully start apps when passive becomes active --- .../middlewared/plugins/failover_/event.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/middlewared/middlewared/plugins/failover_/event.py b/src/middlewared/middlewared/plugins/failover_/event.py index e2388232dbc24..25816870e89ad 100644 --- a/src/middlewared/middlewared/plugins/failover_/event.py +++ b/src/middlewared/middlewared/plugins/failover_/event.py @@ -737,6 +737,8 @@ def vrrp_master(self, job, fobj, ifname, event): self.run_call('kmip.initialize_keys') logger.info('Done syncing encryption keys with KMIP server') + self.start_apps() + logger.info('Migrating interface information (if required)') self.run_call('interface.persist_link_addresses') logger.info('Done migrating interface information (if required)') @@ -938,6 +940,30 @@ def vrrp_backup(self, job, fobj, ifname, event): return self.FAILOVER_RESULT + def start_apps(self): + pool = self.run_call('docker.config')['pool'] + if not pool: + logger.info('Skipping starting apps as they are not configured') + return + + logger.info('Going to initialize apps plugin as %r pool is configured for apps', pool) + logger.info('Mounting relevant docker datasets') + try: + self.run_call('docker.fs_manage.mount') + except Exception: + logger.error('Failed to mount docker datasets', exc_info=True) + return + else: + logger.info('Mounted docker datasets successfully') + + logger.info('Starting docker service') + try: + self.run_call('docker.state.start_service') + except Exception: + logger.error('Failed to start docker service', exc_info=True) + else: + logger.info('Docker service started successfully') + def stop_apps(self): if not self.middleware.call_sync('docker.config')['dataset']: return