diff --git a/api/service_bus.py b/api/service_bus.py index c53a394..cb808d4 100644 --- a/api/service_bus.py +++ b/api/service_bus.py @@ -179,36 +179,45 @@ class ServiceBus: def orchestrate_service_start(self, service_name: str) -> bool: """Orchestrate starting a service with its dependencies""" try: - # Map service names to Docker container names - service_to_container = { - 'wireguard': 'cell-wireguard', - 'email': 'cell-mail', - 'calendar': 'cell-radicale', - 'files': 'cell-webdav', - 'network': 'cell-dns', # DNS is the main network service + # Map service names to Docker container names and their dependencies + service_to_containers = { + 'wireguard': ['cell-wireguard'], + 'email': ['cell-mail', 'cell-rainloop'], # Email service includes both mail server and web client + 'calendar': ['cell-radicale'], + 'files': ['cell-webdav', 'cell-filegator'], # Files service includes both webdav and file manager + 'network': ['cell-dns', 'cell-dhcp', 'cell-ntp'], # Network service includes all network components 'routing': None, # Routing is a system service, not a container 'vault': None, # Vault is part of API, not a separate container 'container': None # Container manager doesn't have its own container } - container_name = service_to_container.get(service_name) + containers = service_to_containers.get(service_name) - if container_name is None: + if containers is None: # For services without containers (routing, vault, container), just call their start method if hasattr(self.service_registry[service_name], 'start'): self.service_registry[service_name].start() logger.info(f"Started service (no container): {service_name}") return True - # For services with containers, start the Docker container + # For services with containers, start all required Docker containers if 'container' in self.service_registry: container_manager = self.service_registry['container'] - success = container_manager.start_container(container_name) - if success: - logger.info(f"Started container {container_name} for service {service_name}") + all_success = True + + for container_name in containers: + success = container_manager.start_container(container_name) + if success: + logger.info(f"Started container {container_name} for service {service_name}") + else: + logger.error(f"Failed to start container {container_name} for service {service_name}") + all_success = False + + if all_success: + logger.info(f"Started all containers for service {service_name}: {containers}") return True else: - logger.error(f"Failed to start container {container_name} for service {service_name}") + logger.error(f"Failed to start some containers for service {service_name}") return False else: logger.error("Container manager not available") @@ -221,36 +230,45 @@ class ServiceBus: def orchestrate_service_stop(self, service_name: str) -> bool: """Orchestrate stopping a service""" try: - # Map service names to Docker container names - service_to_container = { - 'wireguard': 'cell-wireguard', - 'email': 'cell-mail', - 'calendar': 'cell-radicale', - 'files': 'cell-webdav', - 'network': 'cell-dns', # DNS is the main network service + # Map service names to Docker container names and their dependencies + service_to_containers = { + 'wireguard': ['cell-wireguard'], + 'email': ['cell-mail', 'cell-rainloop'], # Email service includes both mail server and web client + 'calendar': ['cell-radicale'], + 'files': ['cell-webdav', 'cell-filegator'], # Files service includes both webdav and file manager + 'network': ['cell-dns', 'cell-dhcp', 'cell-ntp'], # Network service includes all network components 'routing': None, # Routing is a system service, not a container 'vault': None, # Vault is part of API, not a separate container 'container': None # Container manager doesn't have its own container } - container_name = service_to_container.get(service_name) + containers = service_to_containers.get(service_name) - if container_name is None: + if containers is None: # For services without containers (routing, vault, container), just call their stop method if hasattr(self.service_registry[service_name], 'stop'): self.service_registry[service_name].stop() logger.info(f"Stopped service (no container): {service_name}") return True - # For services with containers, stop the Docker container + # For services with containers, stop all required Docker containers if 'container' in self.service_registry: container_manager = self.service_registry['container'] - success = container_manager.stop_container(container_name) - if success: - logger.info(f"Stopped container {container_name} for service {service_name}") + all_success = True + + for container_name in containers: + success = container_manager.stop_container(container_name) + if success: + logger.info(f"Stopped container {container_name} for service {service_name}") + else: + logger.error(f"Failed to stop container {container_name} for service {service_name}") + all_success = False + + if all_success: + logger.info(f"Stopped all containers for service {service_name}: {containers}") return True else: - logger.error(f"Failed to stop container {container_name} for service {service_name}") + logger.error(f"Failed to stop some containers for service {service_name}") return False else: logger.error("Container manager not available")