wip: make work Services Status

This commit is contained in:
Constantin
2025-09-13 14:23:31 +03:00
parent 2277b11563
commit f0b6d1cff1
18 changed files with 2568 additions and 2130 deletions
+64 -31
View File
@@ -179,27 +179,40 @@ class ServiceBus:
def orchestrate_service_start(self, service_name: str) -> bool:
"""Orchestrate starting a service with its dependencies"""
try:
# Check dependencies
dependencies = self.service_dependencies.get(service_name, [])
for dep in dependencies:
if dep not in self.service_registry:
logger.warning(f"Service {service_name} depends on {dep} which is not registered")
# 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
'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)
if container_name 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
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}")
return True
else:
logger.error(f"Failed to start container {container_name} for service {service_name}")
return False
# Run pre-start hooks
if service_name in self.lifecycle_hooks and 'pre_start' in self.lifecycle_hooks[service_name]:
self.lifecycle_hooks[service_name]['pre_start']()
# Start the service
if hasattr(self.service_registry[service_name], 'start'):
self.service_registry[service_name].start()
# Run post-start hooks
if service_name in self.lifecycle_hooks and 'post_start' in self.lifecycle_hooks[service_name]:
self.lifecycle_hooks[service_name]['post_start']()
logger.info(f"Orchestrated start of service: {service_name}")
return True
else:
logger.error("Container manager not available")
return False
except Exception as e:
logger.error(f"Error orchestrating start of {service_name}: {e}")
@@ -208,20 +221,40 @@ class ServiceBus:
def orchestrate_service_stop(self, service_name: str) -> bool:
"""Orchestrate stopping a service"""
try:
# Run pre-stop hooks
if service_name in self.lifecycle_hooks and 'pre_stop' in self.lifecycle_hooks[service_name]:
self.lifecycle_hooks[service_name]['pre_stop']()
# 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
'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
}
# Stop the service
if hasattr(self.service_registry[service_name], 'stop'):
self.service_registry[service_name].stop()
container_name = service_to_container.get(service_name)
# Run post-stop hooks
if service_name in self.lifecycle_hooks and 'post_stop' in self.lifecycle_hooks[service_name]:
self.lifecycle_hooks[service_name]['post_stop']()
if container_name 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
logger.info(f"Orchestrated stop of service: {service_name}")
return True
# For services with containers, stop the Docker container
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}")
return True
else:
logger.error(f"Failed to stop container {container_name} for service {service_name}")
return False
else:
logger.error("Container manager not available")
return False
except Exception as e:
logger.error(f"Error orchestrating stop of {service_name}: {e}")