fix for bus

This commit is contained in:
Constantin
2025-09-13 14:42:32 +03:00
parent de1e1154ce
commit 47c2beaf96
+40 -22
View File
@@ -179,36 +179,45 @@ class ServiceBus:
def orchestrate_service_start(self, service_name: str) -> bool: def orchestrate_service_start(self, service_name: str) -> bool:
"""Orchestrate starting a service with its dependencies""" """Orchestrate starting a service with its dependencies"""
try: try:
# Map service names to Docker container names # Map service names to Docker container names and their dependencies
service_to_container = { service_to_containers = {
'wireguard': 'cell-wireguard', 'wireguard': ['cell-wireguard'],
'email': 'cell-mail', 'email': ['cell-mail', 'cell-rainloop'], # Email service includes both mail server and web client
'calendar': 'cell-radicale', 'calendar': ['cell-radicale'],
'files': 'cell-webdav', 'files': ['cell-webdav', 'cell-filegator'], # Files service includes both webdav and file manager
'network': 'cell-dns', # DNS is the main network service 'network': ['cell-dns', 'cell-dhcp', 'cell-ntp'], # Network service includes all network components
'routing': None, # Routing is a system service, not a container 'routing': None, # Routing is a system service, not a container
'vault': None, # Vault is part of API, not a separate container 'vault': None, # Vault is part of API, not a separate container
'container': None # Container manager doesn't have its own 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 # For services without containers (routing, vault, container), just call their start method
if hasattr(self.service_registry[service_name], 'start'): if hasattr(self.service_registry[service_name], 'start'):
self.service_registry[service_name].start() self.service_registry[service_name].start()
logger.info(f"Started service (no container): {service_name}") logger.info(f"Started service (no container): {service_name}")
return True 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: if 'container' in self.service_registry:
container_manager = self.service_registry['container'] container_manager = self.service_registry['container']
all_success = True
for container_name in containers:
success = container_manager.start_container(container_name) success = container_manager.start_container(container_name)
if success: if success:
logger.info(f"Started container {container_name} for service {service_name}") logger.info(f"Started container {container_name} for service {service_name}")
return True
else: else:
logger.error(f"Failed to start container {container_name} for service {service_name}") 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 some containers for service {service_name}")
return False return False
else: else:
logger.error("Container manager not available") logger.error("Container manager not available")
@@ -221,36 +230,45 @@ class ServiceBus:
def orchestrate_service_stop(self, service_name: str) -> bool: def orchestrate_service_stop(self, service_name: str) -> bool:
"""Orchestrate stopping a service""" """Orchestrate stopping a service"""
try: try:
# Map service names to Docker container names # Map service names to Docker container names and their dependencies
service_to_container = { service_to_containers = {
'wireguard': 'cell-wireguard', 'wireguard': ['cell-wireguard'],
'email': 'cell-mail', 'email': ['cell-mail', 'cell-rainloop'], # Email service includes both mail server and web client
'calendar': 'cell-radicale', 'calendar': ['cell-radicale'],
'files': 'cell-webdav', 'files': ['cell-webdav', 'cell-filegator'], # Files service includes both webdav and file manager
'network': 'cell-dns', # DNS is the main network service 'network': ['cell-dns', 'cell-dhcp', 'cell-ntp'], # Network service includes all network components
'routing': None, # Routing is a system service, not a container 'routing': None, # Routing is a system service, not a container
'vault': None, # Vault is part of API, not a separate container 'vault': None, # Vault is part of API, not a separate container
'container': None # Container manager doesn't have its own 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 # For services without containers (routing, vault, container), just call their stop method
if hasattr(self.service_registry[service_name], 'stop'): if hasattr(self.service_registry[service_name], 'stop'):
self.service_registry[service_name].stop() self.service_registry[service_name].stop()
logger.info(f"Stopped service (no container): {service_name}") logger.info(f"Stopped service (no container): {service_name}")
return True 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: if 'container' in self.service_registry:
container_manager = self.service_registry['container'] container_manager = self.service_registry['container']
all_success = True
for container_name in containers:
success = container_manager.stop_container(container_name) success = container_manager.stop_container(container_name)
if success: if success:
logger.info(f"Stopped container {container_name} for service {service_name}") logger.info(f"Stopped container {container_name} for service {service_name}")
return True
else: else:
logger.error(f"Failed to stop container {container_name} for service {service_name}") 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 some containers for service {service_name}")
return False return False
else: else:
logger.error("Container manager not available") logger.error("Container manager not available")