feat: Settings changes now apply to real service config files and restart containers
Each service manager now has apply_config() that writes to the actual config:
- network: dhcp_range → dnsmasq.conf (reload cell-dhcp), ntp_servers → chrony.conf
(restart cell-ntp), domain → dnsmasq.conf domain= line
- email: domain → mailserver.env OVERRIDE_HOSTNAME + POSTMASTER_ADDRESS,
restart cell-mail
- wireguard: port/address/private_key → wg0.conf ListenPort/Address/PrivateKey,
restart cell-wireguard
- calendar: port → radicale config hosts=, restart cell-radicale
PUT /api/config now calls apply_config() after persisting JSON, and returns
{restarted: [...], warnings: [...]} so Settings UI can show which containers
were restarted. _restart_container() helper added to BaseServiceManager.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -68,11 +68,31 @@ class BaseServiceManager(ABC):
|
||||
"""Restart service - default implementation"""
|
||||
try:
|
||||
self.logger.info(f"Restarting {self.service_name} service")
|
||||
# Default implementation - subclasses can override
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error restarting {self.service_name}: {e}")
|
||||
return False
|
||||
|
||||
def _restart_container(self, container_name: str) -> bool:
|
||||
"""Restart a Docker container by name."""
|
||||
import subprocess
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['docker', 'restart', container_name],
|
||||
capture_output=True, text=True, timeout=30
|
||||
)
|
||||
if result.returncode == 0:
|
||||
self.logger.info(f"Restarted container {container_name}")
|
||||
return True
|
||||
self.logger.error(f"Failed to restart {container_name}: {result.stderr}")
|
||||
return False
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error restarting container {container_name}: {e}")
|
||||
return False
|
||||
|
||||
def apply_config(self, config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Apply config to actual service files and restart. Override in subclasses."""
|
||||
return {'restarted': [], 'warnings': []}
|
||||
|
||||
def get_config(self) -> Dict[str, Any]:
|
||||
"""Get service configuration - default implementation"""
|
||||
|
||||
Reference in New Issue
Block a user